Web3.py – Solving AttributeError: ‘Eth’ Object Has No Attribute ‘Get_block’

web3.py

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'

Best Answer

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.