0

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']
print(block_number)
0

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 '19 at 11:30
  • @Nate: What version of web3.py are you using? – goodvibration Sep 23 '19 at 11:57
  • How long does it wait now before throwing timeout error? Probably you just need to increase timeout even further? – Mikhail Vladimirov Oct 26 '19 at 21:37
0

Try limiting the amount of blocks to 1000

https://community.infura.io/t/getlogs-error-query-returned-more-than-1000-results/358/6

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.

New contributor
user58199 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.