{"action":"created","issue":{"url":"https://api.github.com/repos/ethereum/web3.py/issues/1009","repository_url":"https://api.github.com/repos/ethereum/web3.py","labels_url":"https://api.github.com/repos/ethereum/web3.py/issues/1009/labels{/name}","comments_url":"https://api.github.com/repos/ethereum/web3.py/issues/1009/comments","events_url":"https://api.github.com/repos/ethereum/web3.py/issues/1009/events","html_url":"https://github.com/ethereum/web3.py/issues/1009","id":352031976,"node_id":"MDU6SXNzdWUzNTIwMzE5NzY=","number":1009,"title":"websocket provider not working","user":{"login":"jfdelgad","id":36968968,"node_id":"MDQ6VXNlcjM2OTY4OTY4","avatar_url":"https://avatars1.githubusercontent.com/u/36968968?v=4","gravatar_id":"","url":"https://api.github.com/users/jfdelgad","html_url":"https://github.com/jfdelgad","followers_url":"https://api.github.com/users/jfdelgad/followers","following_url":"https://api.github.com/users/jfdelgad/following{/other_user}","gists_url":"https://api.github.com/users/jfdelgad/gists{/gist_id}","starred_url":"https://api.github.com/users/jfdelgad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfdelgad/subscriptions","organizations_url":"https://api.github.com/users/jfdelgad/orgs","repos_url":"https://api.github.com/users/jfdelgad/repos","events_url":"https://api.github.com/users/jfdelgad/events{/privacy}","received_events_url":"https://api.github.com/users/jfdelgad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-20T08:23:20Z","updated_at":"2018-08-21T03:26:45Z","closed_at":null,"author_association":"NONE","body":"* Version: 4.5\r\n* Python: 3.5\r\n* OS: win\r\n\r\n\r\n### What was wrong?\r\nimpossible to connect to infura using websockets\r\n\r\nI am using this to connect to infura:\r\n\r\nfrom web3 import Web3\r\nweb3 = Web3(Web3.WebsocketProvider(\"wss://ropsten.infura.io/ws\"))\r\nweb3.eth.blockNumber\r\n\r\nNo response, the console just become unresponsive. Tried two different computers in different networks, same result. Also used rinkeby and mainnet, same result.\r\n"},"comment":{"url":"https://api.github.com/repos/ethereum/web3.py/issues/comments/414537934","html_url":"https://github.com/ethereum/web3.py/issues/1009#issuecomment-414537934","issue_url":"https://api.github.com/repos/ethereum/web3.py/issues/1009","id":414537934,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNDUzNzkzNA==","user":{"login":"voith","id":8171193,"node_id":"MDQ6VXNlcjgxNzExOTM=","avatar_url":"https://avatars3.githubusercontent.com/u/8171193?v=4","gravatar_id":"","url":"https://api.github.com/users/voith","html_url":"https://github.com/voith","followers_url":"https://api.github.com/users/voith/followers","following_url":"https://api.github.com/users/voith/following{/other_user}","gists_url":"https://api.github.com/users/voith/gists{/gist_id}","starred_url":"https://api.github.com/users/voith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/voith/subscriptions","organizations_url":"https://api.github.com/users/voith/orgs","repos_url":"https://api.github.com/users/voith/repos","events_url":"https://api.github.com/users/voith/events{/privacy}","received_events_url":"https://api.github.com/users/voith/received_events","type":"User","site_admin":false},"created_at":"2018-08-21T03:26:45Z","updated_at":"2018-08-21T03:26:45Z","author_association":"CONTRIBUTOR","body":"thanks for the report @jfdelgad. \r\nfirstly, the connection should timeout after sometime instead of just hanging and is noted in #956.\r\nI tested my code with `mainnet`, `rinkeby`, `ropsten` and `kovan`. Below are the results.\r\n\r\n##### with mainnet\r\n```python\r\nIn [31]: w3 = Web3(Web3.WebsocketProvider('wss://mainnet.infura.io/_ws'))\r\n\r\nIn [32]: w3.eth.blockNumber\r\nOut[32]: 6184928\r\n```\r\nNotice the `_ws` in the uri.\r\nHowever, when I remove the _ws and try `wss://mainnet.infura.io/ws`, it hangs.\r\n```\r\nIn [33]: w3 = Web3(Web3.WebsocketProvider('wss://mainnet.infura.io/ws'))\r\n\r\nIn [34]: w3.eth.blockNumber\r\n# hangs\r\n```\r\nthen I tried [wscat](https://github.com/websockets/wscat)\r\n```\r\n➜  ~ wscat -c wss://mainnet.infura.io/ws\r\n\r\nconnected (press CTRL+C to quit)\r\n> {\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\",\"params\":[],\"id\": 1}\r\n< {\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x5e5ff9\"}\r\n```\r\nNext tried with the `websockets` library:\r\n```python\r\nimport asyncio\r\nimport json\r\nimport websockets\r\n\r\nasync def get_eth_blockNumber(uri):\r\n    async with websockets.connect(uri) as websocket:\r\n        request_data = {'jsonrpc': '2.0', 'method': 'eth_blockNumber', 'params': [], 'id': 1}\r\n        await websocket.send(json.dumps(request_data))\r\n\r\n        result = await websocket.recv()\r\n        print(result)\r\n\r\nIn [9]: asyncio.get_event_loop().run_until_complete(get_eth_blockNumber('wss://mainnet.infura.io/_ws'))\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x5e6076\"}\r\n\r\nIn [10]: asyncio.get_event_loop().run_until_complete(get_eth_blockNumber('wss://mainnet.infura.io/ws'))\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x5e6077\"}\r\n\r\n\r\nIn [11]: asyncio.get_event_loop().run_until_complete(get_eth_blockNumber('wss://ropsten.infura.io/ws'))\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"0x3b2f70\"}\r\n\r\n```\r\nThis is a bug in web3. I don't when I'll get time to get to this."}}
{"actor":{"display_login":"voith"}}