Web3.eth:溢出错误:Python int 太大而无法转换为 C ssize_t
Posted
技术标签:
【中文标题】Web3.eth:溢出错误:Python int 太大而无法转换为 C ssize_t【英文标题】:Web3.eth: OverflowError: Python int too large to convert to C ssize_t 【发布时间】:2021-01-22 14:27:43 【问题描述】:我正在尝试获取各种代币合约的符号,但其中一些我收到以下错误:
OverflowError: Python int 太大,无法转换为 C ssize_t
这是一个最小的可重现示例:
from web3 import Web3
import json
web3 = Web3(Web3.HTTPProvider('https://cloudflare-eth.com'))
address = '0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2'
abi = json.loads(
'["constant":true,"inputs":[],"name":"name","outputs":["name":"","type":"string"],"payable":false,"stateMutability":"view","type":"function","constant":false,"inputs":["name":"_spender","type":"address","name":"_value","type":"uint256"],"name":"approve","outputs":["name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":true,"inputs":[],"name":"totalSupply","outputs":["name":"","type":"uint256"],"payable":false,"stateMutability":"view","type":"function","constant":false,"inputs":["name":"_from","type":"address","name":"_to","type":"address","name":"_value","type":"uint256"],"name":"transferFrom","outputs":["name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":true,"inputs":[],"name":"decimals","outputs":["name":"","type":"uint8"],"payable":false,"stateMutability":"view","type":"function","constant":true,"inputs":["name":"_owner","type":"address"],"name":"balanceOf","outputs":["name":"","type":"uint256"],"payable":false,"stateMutability":"view","type":"function","constant":true,"inputs":[],"name":"symbol","outputs":["name":"","type":"string"],"payable":false,"stateMutability":"view","type":"function","constant":false,"inputs":["name":"_to","type":"address","name":"_value","type":"uint256"],"name":"transfer","outputs":["name":"","type":"bool"],"payable":false,"stateMutability":"nonpayable","type":"function","constant":true,"inputs":["name":"_owner","type":"address","name":"_spender","type":"address"],"name":"allowance","outputs":["name":"","type":"uint256"],"payable":false,"stateMutability":"view","type":"function","anonymous":false,"inputs":["indexed":true,"name":"_from","type":"address","indexed":true,"name":"_to","type":"address","indexed":false,"name":"_value","type":"uint256"],"name":"Transfer","type":"event","anonymous":false,"inputs":["indexed":true,"name":"_owner","type":"address","indexed":true,"name":"_spender","type":"address","indexed":false,"name":"_value","type":"uint256"],"name":"Approval","type":"event"]') # noqa: 501
symbol = web3.eth.contract(address=address, abi=abi).functions.symbol().call()
我不知道为什么会出现此错误,尤其是考虑到它适用于某些合同但不适用于其他合同。任何帮助将不胜感激!
【问题讨论】:
见“OverflowError: Python int too large to convert to C long” on windows but not @ShivamJha 我有点不清楚我的代码中可以从 int 切换到 float 的位置,以及为什么它目前适用于某些合同而不适用于其他合同。 【参考方案1】:此特定标记将符号返回为 bytes32,因此更改符号函数的类型解决了问题。
【讨论】:
并将字节解码为字符串:name = t.name().decode('utf-8') symbol = t.symbol().decode('utf-8')以上是关于Web3.eth:溢出错误:Python int 太大而无法转换为 C ssize_t的主要内容,如果未能解决你的问题,请参考以下文章
web3.eth.accounts.decrypt 在 cryp.createDecipheriv 抛出错误
web3.eth.sendSignedTransaction() 总是返回“返回错误:nonce 太低”
带有 ganache-cli 的 web3.eth.getTransaction 给出了 chainId 错误
调用 web3.eth.personal.unlockAccount 会抛出错误
让 accounts = web3.eth.getAccounts() 显示未定义和 app.vote(1, from: accounts[1] ) 显示错误