Closed KonradStaniec closed 2 years ago
import chronos, uri, chronos/apps/http/httpclient, stew/byteutils
let resp = waitFor HttpSessionRef.new().fetch(parseUri("https://eth-goerli.g.alchemy.com/v2/api-key"))
echo string.fromBytes(resp.data)
Works fine, so this is either coming from nim-web3, nim-websock or buggy server
There are two issues:
For (2), workaround is here: https://github.com/status-im/nim-json-rpc/pull/148
Using the nim-json-rpc
and nim-websock
from linked issues above, the stacktrace now indicates missing API token instead:
/Users/etan/Documents/Repos/nimbus-eth2/test.nim(4) test
vendor/nim-chronos/chronos/asyncloop.nim(1127) waitFor
vendor/nim-chronos/chronos/asyncloop.nim(289) poll
vendor/nim-chronos/chronos/asyncfutures2.nim(365) futureContinue
vendor/nim-websock/websock/websock.nim(172) connect
[[reraised from:
/Users/etan/Documents/Repos/nimbus-eth2/test.nim(4) test
vendor/nim-chronos/chronos/asyncloop.nim(1127) waitFor
vendor/nim-chronos/chronos/asyncloop.nim(289) poll
vendor/nim-chronos/chronos/asyncfutures2.nim(365) futureContinue
vendor/nim-chronos/chronos/asyncmacro2.nim(288) connect
vendor/nim-chronos/chronos/asyncfutures2.nim(502) internalCheckComplete
]]
[[reraised from:
/Users/etan/Documents/Repos/nimbus-eth2/test.nim(4) test
vendor/nim-chronos/chronos/asyncloop.nim(1127) waitFor
vendor/nim-chronos/chronos/asyncloop.nim(289) poll
vendor/nim-chronos/chronos/asyncfutures2.nim(365) futureContinue
vendor/nim-chronos/chronos/asyncmacro2.nim(288) newWeb3
vendor/nim-chronos/chronos/asyncfutures2.nim(502) internalCheckComplete
]]
[[reraised from:
/Users/etan/Documents/Repos/nimbus-eth2/test.nim(4) test
vendor/nim-chronos/chronos/asyncloop.nim(1129) waitFor
vendor/nim-chronos/chronos/asyncfutures2.nim(515) read
vendor/nim-chronos/chronos/asyncfutures2.nim(502) internalCheckComplete
]]
Error: unhandled exception: Server did not reply with a websocket upgrade: Header code: 401 Header reason: Unauthorized Address: [2606:4700::6812:d3f]:443 [WSFailedUpgradeError]
yup, tested with my api token that both those fixes resolve situation.
Small repro:
Instead of success it ends up with:
Full stacktrace:
Ultimately what throws this initial exceptions is: https://github.com/status-im/nim-websock/blob/main/websock/http/client.nim#L108
When I tested this url with
news
or any other websocket client it worked correctly.