2

I'm trying to get all events from contract, but get error: "ValueError: {'code': -32601, 'message': 'The method eth_newFilter does not exist/is not available'}"

I'm using Web3py and Infura. My code:

myfilter = <myContract>.events.<MyEvent>.createFilter(fromBlock=0)

or

myFilter = web3.eth.filter({"address": <myContractAddress>})

Why is this error? How do I get events? Help me please.

  • 1
    How are you connecting to Infura? eth_newFilter is only available via websocket. – iamdefinitelyahuman Dec 4 '19 at 12:12
  • Like this: from web3 import Web3 PROVIDER = 'https://ropsten.infura.io/v3/xxxxxxxxxxx' web3 = Web3(Web3.HTTPProvider(PROVIDER)) – Alex Dec 4 '19 at 13:03
  • @iamdefinitelyahuman So I don't know why this error. As you can see in the code, I use Infura. – Alex Dec 4 '19 at 13:06
2

The issue is that Infura only exposes the eth_newFilter endpoint via websockets, but you are connecting via https.

Try using a WebsocketProvider when declaring your web3 instance, as shown in the following example:

from web3 import Web3

PROVIDER = "wss://ropsten.infura.io/ws/v3/YOUR-PROJECT-ID"
web3 = Web3(Web3.WebsocketProvider(PROVIDER))
|improve this answer|||||
  • Will all other methods work correctly? (via WebsocketProvider) And it will not affect speed of working with Infura? – Alex Dec 4 '19 at 15:30
  • 1
    Yes, per the infura docs all https endpoints will be available. And websockets is typically quicker. – iamdefinitelyahuman Dec 4 '19 at 15:42
  • Thank you! But I have other error – Alex Dec 4 '19 at 16:54
  • "websockets.exceptions.InvalidStatusCode: Status code not 101: 404" – Alex Dec 4 '19 at 16:56
  • 1
    ahh sorry, i made a mistake in the provider URL! I've updated my answer. – iamdefinitelyahuman Dec 5 '19 at 3:03

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.