When I run the following code sometimes it executes successfully, but most of the time it raises a concurrent.futures._base.TimeoutError. What can I do to fix this?

Here is the code:

infura_url_ws = 'wss://mainnet.infura.io/ws/v3/MY-PROJECT-ID'
ws3 = Web3(Web3.WebsocketProvider(infura_url_ws))

abi = [{"name": "NewExchange", "inputs": [{"type": "address", "name": "token", "indexed": True}, {"type": "address", "name": "exchange", "indexed": True}], "anonymous": False, "type": "event"}] 
uniswap = ws3.eth.contract('0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95', abi=abi)

events = uniswap.events.NewExchange.createFilter(fromBlock=8567919).get_all_entries()
block_number = events[0]['blockNumber']

4 Answers 4


Try limiting the amount of blocks to 1000


A infura dev mentions:

We currently limit response to blocks of 1000 responses, https://infura.io/docs/ethereum/json-rpc/eth_getLogs 90, the limitations are outlined in this doc.

Limiting the amount of blocks worked for me.


web3.py requires the parameter websocket_timeout=60 for a WebsocketProvider:

from web3 import Web3
w3 = Web3(Web3.WebsocketProvider("ws://", websocket_timeout=60))

If you're using HTTP, you set request_kwargs={'timeout':60} instead:

from web3 import Web3
w3 = Web3(Web3.HTTPProvider("", request_kwargs={'timeout': 60}))

Documentation: https://web3py.readthedocs.io/en/stable/providers.html


Any too large response from commercial node providers will time out, because their servers cannot handle the request due to it blocking other customers.


Try this:

ws3 = Web3(Web3.WebsocketProvider(infura_url_ws,request_kwargs={'timeout':60}))

If I remember correctly, the default timeout is 10 (seconds).

  • Thanks. I tried, but it still does not work.
    – Nate
    Sep 23, 2019 at 11:30
  • @Nate: What version of web3.py are you using? Sep 23, 2019 at 11:57
  • How long does it wait now before throwing timeout error? Probably you just need to increase timeout even further? Oct 26, 2019 at 21:37
  • This is incorrect syntax for a websocketprovider. see web3py.readthedocs.io/en/stable/providers.html
    – fafrd
    Oct 6, 2021 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.