5.0.1,Python:3.6.3下面的代码是在web3==4.9.2上运行的,它不适用于web3==5.0.1。我收到以下错误:
web3.middleware_stack.inject(geth_poa_middleware, layer=0)
AttributeError: 'Web3' object has no attribute 'middleware_stack'示例代码:
#!/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')发布于 2019-08-19 16:01:00
Web3.middleware_onion.add(middleware, name=None)
用web3.middleware_stack.inject(geth_poa_middleware, layer=0)代替web3.middleware_onion.inject(geth_poa_middleware, layer=0)解决了这个问题。
https://ethereum.stackexchange.com/questions/74044
复制相似问题