1
  • web3.py version: 5.0.1 , Python: 3.6.3

Following code was working on web3==4.9.2, which does not work for the web3==5.0.1. I am getting following error:

    web3.middleware_stack.inject(geth_poa_middleware, layer=0)
AttributeError: 'Web3' object has no attribute 'middleware_stack'

Example piece of code:

#!/usr/bin/env python3
from web3 import Web3
from web3.providers.rpc import HTTPProvider
from web3 import Web3, IPCProvider

web3 = Web3(IPCProvider('/private/geth.ipc'))
from web3.middleware import geth_poa_middleware
# inject the poa compatibility middleware to the innermost layer
web3.middleware_stack.inject(geth_poa_middleware, layer=0)
from web3.shh import Shh
Shh.attach(web3, 'shh')
1

Web3.middleware_onion.add(middleware, name=None)

Replacing web3.middleware_stack.inject(geth_poa_middleware, layer=0) with web3.middleware_onion.inject(geth_poa_middleware, layer=0) fixed the problem.

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.