2

So... I'm probably being super dumb - but I started using web3.py in a jupyter notebook and it connects to the node just fine... but I can't seem to use any .eth methods as it throws a: AttributeError: 'Eth' object has no attribute 'get_block'

Versions:

  • w3.api '5.0.0'
  • Python: 3.9.1
  • OS: osx
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('http://fullnode.dappnode:8545'))

w3.isConnected() returns True, and I can use w3.api and w3.clientVersion just fine... but when I try to do something eth related I get:

>>> w3.eth.get_block('latest')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-70b856a4c410> in <module>
----> 1 w3.eth.get_block('latest')

AttributeError: 'Eth' object has no attribute 'get_block'

or

w3.eth.chain_id
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-23-9e974a6bb0e9> in <module>
----> 1 w3.eth.chain_id

AttributeError: 'Eth' object has no attribute 'chain_id'

3 Answers 3

1

Had the same problem. Apparently we installed an older version of Web3 that used to have the method getBlock, now deprecated in favor of the get_block method.

However I don't know how to upgrade to the latest version, tried using pip install Web3 --upgrade but nothing changes.

1
  • It all came down to a virtualenv mess. For some reason it was using a globally installed web3 version (5.0.0) instead of the documented one that I was following the quickstart for (latest). Nuking the virtualenv and starting from scratch with the new version worked for me :)
    – Lanski
    Commented Apr 10, 2021 at 21:12
1

It all came down to a virtualenv mess. For some reason it was using a globally installed web3 version (5.0.0) instead of the documented one that I was following the quickstart for (latest). Nuking the virtualenv and starting from scratch with the new version worked for me :)

0

In web3 v6, all camelCase methods were updated to use snake_case. You can check which version of web3 you are using with the following command:

python3 -m pip show web3

If you see a version < 6.0.0, you will need to upgrade web3.

python3 -m pip install web3 -U

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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