1

I'm trying to grab the symbols of various token contracts, but for some of them I get the following error:

OverflowError: Python int too large to convert to C ssize_t

Here is a minimal reproducible example:

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()

I have no clue why I'm getting this error, especially considering it works for some contracts but not others. Any help would be appreciated!

rgswope
  • 115
  • 1
  • 9
  • See [“OverflowError: Python int too large to convert to C long” on windows but not](https://stackoverflow.com/questions/38314118/overflowerror-python-int-too-large-to-convert-to-c-long-on-windows-but-not-ma) – Shivam Jha Oct 07 '20 at 15:28
  • @ShivamJha I'm a little unclear about where in my code I could switch from int to float, and also why it currently works for some contracts but not others. – rgswope Oct 07 '20 at 16:08

1 Answers1

2

This specific token was returning the symbol as bytes32, so changing the type of the symbol function fixed the issue.

rgswope
  • 115
  • 1
  • 9