-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
websocket provider not working #1009
Comments
thanks for the report @jfdelgad. on mainnetIn [31]: w3 = Web3(Web3.WebsocketProvider('wss://mainnet.infura.io/_ws'))
In [32]: w3.eth.blockNumber
Out[32]: 6184928 Notice the
then I tried wscat
Next I tried with the import asyncio
import json
import websockets
async def get_eth_blockNumber(uri):
async with websockets.connect(uri) as websocket:
request_data = {'jsonrpc': '2.0', 'method': 'eth_blockNumber', 'params': [], 'id': 1}
await websocket.send(json.dumps(request_data))
result = await websocket.recv()
print(result)
In [9]: asyncio.get_event_loop().run_until_complete(get_eth_blockNumber('wss://mainnet.infura.io/_ws'))
{"jsonrpc":"2.0","id":1,"result":"0x5e6076"}
In [10]: asyncio.get_event_loop().run_until_complete(get_eth_blockNumber('wss://mainnet.infura.io/ws'))
{"jsonrpc":"2.0","id":1,"result":"0x5e6077"}
In [11]: asyncio.get_event_loop().run_until_complete(get_eth_blockNumber('wss://ropsten.infura.io/ws'))
{"jsonrpc":"2.0","id":1,"result":"0x3b2f70"} This is a bug in web3. I don't know when I'll get time to get to this. |
Thanks a lot, this is useful. |
Bump! Same issue here except both There is an official document from infura that the de facto WebSocket URL should be the one without underscore, I have tried on both mainnet and rinkey ( |
Yes, I am suffering from the same issue. |
Will try my best to take a look at this tonight. But not promising anything. |
It turns out that this line is creating the problem: web3.py/web3/providers/websocket.py Line 99 in baaafca
encode_rpc_request(method, params) returns bytes which for some reason causes infura to barf.(Not sure yet if the problem is with infura, but the same code works fine with geth and parity)df465dc seems to fix the issue, but I need to investigate further. |
So this indeed turns out to be a bug in infura. Websocket supports input as both string and binary. However, the opcodes for both differ in the DataFrame. You can look at the implementation here or read it up in the docs. This is not a bug in web3 but a bug in infura. We can still fix this in web3 as a temporary workaround, something like df465dc. But let @carver and @pipermerriam make this call. |
Sure, a |
Infura decided to fix this on their end: INFURA/infura#134 (comment). I tested it myself, works fine! @carver We can now close this issue. |
@voith checked this on my end works fine. |
Nice @voith |
I'm unable to connect to wss
|
@Daiiszuki it looks like you're using an infura project id as your URL. You need a URL that looks something like:
and similarly for a testnet: In the future, this kind of usage question is usually best for the web3.py discord channel here. If you think you've found a bug and want to raise an issue, please open a new issue rather than commenting on an old one. Thanks! |
Thanks for responding but the .env variable actually contains the full infura url.I used this issue because I believe it's the same problem I've tried the suggestions here, nothing seems to work |
And I did try the discord group and no response, but made some improvements to the code:
**I Need a way to continuously monitor the price of uniswap pair reserves -->To be used in another program Please if you can link me to an an example implementation.By the way. The above code produces:**
|
Hey were you able to solve this? I have run into the same error. |
What was wrong?
impossible to connect to infura using websockets
I am using this to connect to infura:
from web3 import Web3
web3 = Web3(Web3.WebsocketProvider("wss://ropsten.infura.io/ws"))
web3.eth.blockNumber
No response, the console just become unresponsive. Tried two different computers in different networks, same result. Also used rinkeby and mainnet, same result.
The text was updated successfully, but these errors were encountered: