niv / websocket.nim

websockets for nim
http://niv.github.io/websocket.nim/docs/0.1.1/websocket.html
Other
102 stars 25 forks source link

Server did not reply with a websocket upgrade: 400 Bad Request #58

Closed Adnan206 closed 5 years ago

Adnan206 commented 5 years ago

I've used a discord nim library and when I run the file I get this error

lib code: https://github.com/Krognol/discordnim/blob/master/src/discord.nim#L403

Hint: operation successful (96991 lines compiled; 84.867 sec total; 282.539MiB peakmem; Debug Build) [SuccessX]
Hint: C:\Users\Rizwan\Desktop\Projects\Nim!\test.exe  [Exec]
Server did not reply with a websocket upgrade: 400 Bad Request
Async traceback:
  C:\Users\Rizwan\Desktop\Projects\Nim!\test.nim(14)                                test
  C:\Users\Rizwan\.choosenim\toolchains\nim-0.20.0\lib\pure\asyncdispatch.nim(1839) waitFor
  C:\Users\Rizwan\.choosenim\toolchains\nim-0.20.0\lib\pure\asyncdispatch.nim(1533) poll
  C:\Users\Rizwan\.choosenim\toolchains\nim-0.20.0\lib\pure\asyncdispatch.nim(373)  runOnce
  C:\Users\Rizwan\.choosenim\toolchains\nim-0.20.0\lib\pure\asyncdispatch.nim(210)  processPendingCallbacks
  C:\Users\Rizwan\.choosenim\toolchains\nim-0.20.0\lib\pure\asyncmacro.nim(34)      newAsyncWebsocketClient_continue
  C:\Users\Rizwan\.nimble\pkgs\websocket-0.3.6\websocket\client.nim(95)             newAsyncWebsocketClientIter
Exception message: Server did not reply with a websocket upgrade: 400 Bad Request
Exception type:
dom96 commented 5 years ago

Did it work before? Add some code in here to echo the uri and double check it's correct: https://github.com/niv/websocket.nim/blob/master/websocket/client.nim#L92

Adnan206 commented 5 years ago

It didn't work before and this is what shows me wss://gateway.discord.gg:443//?v=7&encoding=json

Adnan206 commented 5 years ago

Before parseUri it was wss://gateway.discord.gg/?v=7&encoding=json

metagn commented 5 years ago

The response is

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>cloudflare</center>
</body>
</html>

httpclient only looks for https, not wss. Reverted #57 and updated Nimble version. Really shouldn't have updated the Nimble version without checking the PR first lol, not gonna do that from now on

Adnan206 commented 5 years ago

Oof

dom96 commented 5 years ago

You really shouldn't have reverted it and released yet another Nimble version... especially since apparently this code didn't work before my change

Adnan206 commented 5 years ago

I installed nimble 0.4.0 and when I run the file I get this

C:\Users\Rizwan\.nimble\pkgs\websocket-0.4.0\websocket\client.nim(106, 34) Error: type mismatch: got <userAgent: string, sslContext: SslContext>
but expected one of:
proc newAsyncHttpClient(userAgent = defUserAgent; maxRedirects = 5;
                       sslContext = getDefaultSSL(); proxy: Proxy = nil): AsyncHttpClient
  first type mismatch at position: 2
  required type: int
  but expression 'sslContext = sslContext' is of type: SslContext

expression: newAsyncHttpClient(userAgent = userAgent, sslContext = sslContext)
metagn commented 5 years ago

God damn it

metagn commented 5 years ago

Should work now. Also youre supposed to add -d:ssl for discord