You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Web3.py调用getTransactionCount报错:'Eth'对象无该属性

解决AttributeError: 'Eth' object has no attribute 'getTransactionCount'错误

问题原因

Web3.py从v6版本开始,将所有以太坊相关API方法的命名从驼峰式(如getTransactionCount)统一改为蛇形命名(如get_transaction_count),你的代码使用了旧版的驼峰命名方法,导致在新版本Web3.py中找不到对应的属性。

解决方案

直接将代码中的方法调用改为蛇形命名即可:

将原代码中的:

nonce = w3.eth.getTransactionCount(my_address)

替换为:

nonce = w3.eth.get_transaction_count(my_address)

额外验证步骤

可以通过以下命令查看当前安装的Web3.py版本,确认是否为v6及以上:

pip show web3

如果确实是v6+版本,所有类似的驼峰命名方法(如sendTransaction、getBalance等)都需要同步改为蛇形命名(send_transaction、get_balance)。

内容的提问来源于stack exchange,提问作者Elena 46

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 08:12:25