【问题标题】:'property' object is not callable“属性”对象不可调用
【发布时间】:2018-09-05 19:35:21
【问题描述】:

所以我已经连接到一个合同,这似乎工作正常,我正在尝试使用这个类:来自https://web3py.readthedocs.io/en/stable/web3.personal.html 的 web3.personal.Personal 我似乎不明白我错了什么......当我 print(web3.personal.Personal) 给我一个类对象但我似乎无法使用与这个类相关的任何函数时,说我缺少“self”参数

contract_abi = my_abi
w3 = Web3(HTTPProvider(myurl))
myContract = w3.eth.contract(address ,abi)
ref = ref = web3.personal.Personal('web3')
print(ref) #this works   
print(ref.newAccount(password='the-passphrase')) #This crashes

TypeError: newAccount() missing 1 required positional argument: 'self'
TypeError: 'property' object is not callable

【问题讨论】:

  • 你可能需要构造一个Personal,所以ref = web3.personal.Personal()
  • 实例由self 表示,类不是
  • 所以当我执行 web3.personal.Personal 时,我没有收到错误,但是当我执行 web3.personal.Personal() 时,我收到错误...

标签: python django ethereum web3


【解决方案1】:

看来web3.personal.Personal是一个类,所以要创建一个对象你需要说ref = web3.personal.Personal()

请注意,课程通常(但不总是)用大写字母书写。

【讨论】:

  • 更新:ref = web3.personal.Personal('web3') 我需要添加 'web3' 作为参数,但是我不能从这个类调用函数
  • 如果你说ref = web3.personal.Personal('web3'),那么 ref 就是 web3.personal.Personal 的一个对象。所以你可以调用对象的函数,而不是类。您是否可能要使用 web3 类的 w3 对象而不是 web3 类来创建 ref
  • 所以在文档中,有一些与 web3.personal 相关的方法:web3py.readthedocs.io/en/stable/web3.personal.html web3.personal.importRawKey(self, private_key, passphrase) 例如,我无法在 ref 上调用这些方法
猜你喜欢
  • 2016-03-21
  • 2022-01-23
  • 2020-01-22
  • 2017-08-06
  • 1970-01-01
  • 2019-09-13
  • 2021-08-21
  • 2010-09-24
相关资源
最近更新 更多