web3.py: InsufficientDataBytes: Tried to read 32 bytes. Only got 0 bytes (This One Appears To Be Different)
Web3 Version: 4.8.2 Solidity: 0.4.18, 0.5.3 (Both Installed Via Py-Solc) Geth Version: 1.7 (Built From Source), 1.8.23 (Binary), Master (as of 2/23/19) (Built From Source)
- Python: 3.6
- OS: Ubuntu 18.04
pip freeze
output
aenum==2.1.2
asn1crypto==0.24.0
astor==0.7.1
attrdict==2.0.0
attrs==18.2.0
Automat==0.7.0
autopep8==1.4.3
base58==1.0.3
bitcoin==1.1.42
blessings==1.7
bpython==0.17.1
bumpversion==0.5.3
certifi==2018.11.29
cffi==1.11.5
chardet==3.0.4
Click==7.0
colorlog==4.0.2
constantly==15.1.0
coverage==4.5.2
coveralls==1.5.1
coz-bytecode==0.5.1
cryptography==2.4.2
curtsies==0.3.0
cycler==0.10.0
cytoolz==0.9.0.1
docopt==0.6.2
ecdsa==0.13
eth-abi==1.3.0 (I just updated this from 1.2.2 in hopes of the issue being solved)
eth-account==0.3.0
eth-hash==0.2.0
eth-keyfile==0.5.1
eth-keys==0.2.0b3
eth-rlp==0.1.2
eth-typing==2.0.0
eth-utils==1.3.0
Events==0.3
Flask==1.0.2
Flask-Cors==3.0.7
Flask-Limiter==1.0.1
Flask-REST==1.3
furl==2.0.0
gevent==1.4.0
greenlet==0.4.15
hexbytes==0.1.0
hyperlink==18.0.0
idna==2.8
incremental==17.5.0
inflection==0.2.0
itsdangerous==1.1.0
Jinja2==2.10
klein==17.10.0
limits==1.3
logzero==1.5.0
lru-dict==1.1.6
MarkupSafe==1.1.0
memory-profiler==0.55.0
mmh3==2.5.1
mock==2.0.0
Mongothon==0.8.0
mpmath==1.1.0
neo-boa==0.5.6
-e git+https://github.com/CityOfZion/neo-python.git@fe90f62e123d720d4281c79af0598d9df9e776fb#egg=neo_python
neo-python-rpc==0.2.1
neocore==0.5.6
orderedmultidict==1.0
parse==1.9.0
parsimonious==0.8.1
pbr==5.1.1
peewee==3.8.1
pexpect==4.6.0
pluggy==0.8.1
plyvel==1.0.5
prompt-toolkit==2.0.7
psutil==5.4.8
ptyprocess==0.6.0
py==1.7.0
py-solc==2.1.0
pycodestyle==2.4.0
pycparser==2.19
pycryptodome==3.7.2
Pygments==2.3.1
PyHamcrest==1.9.0
pymitter==0.2.3
pymongo==3.7.2
Pympler==0.6
pyparsing==2.3.1
python-dateutil==2.7.5
pytz==2018.9
requests==2.21.0
rlp==1.0.3
Schemer==0.2.11
scrypt==0.8.6
semantic-version==2.6.0
six==1.12.0
toolz==0.9.0
tqdm==4.29.1
Twisted==18.9.0
typing==3.6.6
urllib3==1.24.1
uuid==1.30
virtualenv==16.2.0
wcwidth==0.1.7
web3==4.8.2
websockets==6.0
Werkzeug==0.14.1
zope.interface==4.6.0
What was wrong?
I have had this specific contract deployed on Ropsten for just over a month but the exact same code has been deployed and used many times (at least 4 different successful deployments). About 4 days ago seemingly out of nowhere the error “InsufficientDataBytes: Tried to read 32 bytes. Only got 0 bytes” arose. The contract had been used for about 26 days consecutively. There was literally no change in the code base between the contract communication working and it no longer working. I have not found ANY reason as to why this happened.
I wanted to make sure this was not somehow a delayed result of a faulty smart contract so I have confirmed that the exact same issue happens with the example code below. Because I received the exact same issue with the example code I chose to show the example code for simplicity:
import json
import web3
from web3 import Web3
from solc import compile_source
from web3.contract import ConciseContract
contract_source_code = '''
pragma solidity ^0.4.18;
contract Greeter {
string public greeting;
function Greeter() public {
greeting = 'Hello';
}
function setGreeting(string _greeting) public {
greeting = _greeting;
}
function greet() view public returns (string) {
return greeting;
}
}
'''
compiled_sol = compile_source(contract_source_code)
contract_interface = compiled_sol['<stdin>:Greeter']
w3 = Web3(Web3.HTTPProvider('http://localhost:8545'))
w3.eth.defaultAccount = w3.eth.accounts[0]
w3.personal.unlockAccount(w3.personal.listAccounts[0], "password")
print(w3.eth.defaultAccount)
Greeter = w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])
tx_hash = Greeter.constructor().transact()
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)
greeter = w3.eth.contract(
address=tx_receipt.contractAddress,
abi=contract_interface['abi'],
)
print('Default contract greeting: {}'.format(
greeter.functions.greet().call()
))
print('Setting the greeting to Nihao...')
tx_hash = greeter.functions.setGreeting('Nihao').transact()
w3.eth.waitForTransactionReceipt(tx_hash)
print('Updated contract greeting: {}'.format(
greeter.functions.greet().call()
))
reader = ConciseContract(greeter)
assert reader.greet() == "Nihao"
Here is the traceback:
Traceback (most recent call last):
Traceback (most recent call last):
File "ENVPATH/lib/python3.6/site-packages/web3/contract.py", line 1374, in call_contract_function
output_data = decode_abi(output_types, return_data)
File "ENVPATH/lib/python3.6/site-packages/eth_abi/abi.py", line 96, in decode_abi
return decoder(stream)
File "ENVPATH/lib/python3.6/site-packages/eth_abi/decoding.py", line 118, in __call__
return self.decode(stream)
File "ENVPATH/lib/python3.6/site-packages/eth_utils/functional.py", line 46, in inner
return callback(fn(*args, **kwargs))
File "ENVPATH/lib/python3.6/site-packages/eth_abi/decoding.py", line 164, in decode
yield decoder(stream)
File "ENVPATH/lib/python3.6/site-packages/eth_abi/decoding.py", line 118, in __call__
return self.decode(stream)
File "ENVPATH/lib/python3.6/site-packages/eth_abi/decoding.py", line 133, in decode
start_pos = decode_uint_256(stream)
File "ENVPATH/lib/python3.6/site-packages/eth_abi/decoding.py", line 118, in __call__
return self.decode(stream)
File "ENVPATH/lib/python3.6/site-packages/eth_abi/decoding.py", line 186, in decode
raw_data = self.read_data_from_stream(stream)
File "ENVPATH/lib/python3.6/site-packages/eth_abi/decoding.py", line 296, in read_data_from_stream
len(data),
eth_abi.exceptions.InsufficientDataBytes: Tried to read 32 bytes. Only got 0 bytes
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "PROJECTPATH/testContract.py", line 67, in <module>
greeter.functions.greet().call()
File "ENVPATH/lib/python3.6/site-packages/web3/contract.py", line 1115, in call
**self.kwargs
File "ENVPATH/lib/python3.6/site-packages/web3/contract.py", line 1396, in call_contract_function
raise BadFunctionCallOutput(msg) from e
web3.exceptions.BadFunctionCallOutput: Could not decode contract function call greet return data b'' for output_types ['string']
How can it be fixed?
I have no idea at the moment.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 29 (7 by maintainers)
Here is what fixed it for me, for all solc versions, in both geth and parity: When invoking the compiler, the evmVersion must be set to the correct level depending on the Solidity version. In my case, the Docker image of geth must still use evmVersion : ‘byzantium’, while the parity version, as explained on their web site, is using the latest, ‘petersburg’.
see the following for full explanation:
https://solidity.readthedocs.io/en/v0.5.8/using-the-compiler.html#setting-the-evm-version-to-target
I wiped all Ethereum based modules from my venv and reinstalled them. That did not solve the issue. I then wiped geth completely off my computer and built from source (once master and then again with 1.8). This produced an odd issue where contract deployments would show in my geth console but would not be relayed to the network. I have now wiped all the chain data from my computer and am resyncing in fast mode. I will update after the chain has synced and I can fully test this issue again.
@davesque Thanks! I know that doesn’t solve my issue but it helps me narrow the problem down. After hearing that I’ll start by purging all of my web3 related modules and reinstall from scratch. If that doesn’t work I’ll wipe geth, solidity, and my chain and reinstall from scratch. If none of that works I’ll update here with more information.