python - 如何修复 web3 模块 AttributeError?

标签 python ethereum web3py

我正在尝试在 python 中使用 web3。

我正在尝试按照 http://web3py.readthedocs.io/en/stable/web3.eth.html#web3.eth.Eth 中的步骤操作

import web3
web3.eth.getBlock("1028201")

但是得到了

AttributeError: module 'web3.eth' has no attribute 'getBlock'

我在 python 3 和 python 2.7 中都尝试过,得到了相同的结果。

有什么建议吗?

最佳答案

您使用的语法是错误的, 属性 eth 属于 WEB3 对象,而不是类本身 试试这个,它会起作用


from web3 import Web3
# Create an object from the WEB3 lib
w3 = Web3(Web3.IPCProvider())

#then use the eth attribute on it
w3.eth.getBlock("1028201")

关于python - 如何修复 web3 模块 AttributeError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48181275/

相关文章:

ethereum - 为什么这个 Solidity 函数在断言后返回 0?

python - 尝试从 chainlink 导入时 brownie-config 重新映射错误

ethereum - 使用 w3.eth.contract() 部署智能合约时出错 : "The method eth_sendTransaction is not supported"

python - 使用 Web3 和 Python 计算 BSC 代币的价格

python - 如何扩展pyserial的输入缓冲区大小

python - 如何使用特定步长的窗口提取短序列?

java - Web3J |找不到源 "@openzeppelin/contracts/token/ERC721/ERC721.sol": File not found

solidity - 如何检查或知道钱包在 web3 python 中有 token

Python:检测输入仅适用于 1 个字符长的字符串

python - 使用 Tweepy 搜索 Twitter 源