Web3.py: eth_abi.exceptions.EncodingTypeError: Value of type <class 'str'> cannot be encoded by AddressEncoder

Created on 24 Jul 2018  路  1Comment  路  Source: ethereum/web3.py

  • Version: 4.4.1
  • Python: 3.5
  • OS: linux

My smartContract code event section:

    event LogJob(address indexed clusterAddress,
                 string jobKey,
                 uint index,
                 uint8 storageID,        
                 string desc
         );

Web3.py source code:

       blockReadFrom = 1899690;
       myFilter = eBlocBroker.events.LogJob.createFilter(
           fromBlock=blockReadFrom,
           argument_filters={'clusterAddress': '0x75a4c787c5c18c587b284a904165ff06a269b48c2'}
       )
       print(myFilter.get_all_entries()) 

=> First I have created an event with:
clusterAddress: '0x4e4a0750350796164D8DefC442a712B7557BF282'.

This works if 0x4e4a0750350796164D8DefC442a712B7557BF282 exists on emitted event but when I give a non-existed clusterAddress such as (0x4e4a0750350796164D8DefC442a712B7557BF281) ending with 81 instead of 82; I have face with the following error: eth_abi.exceptions.EncodingTypeError: Value of type <class 'str'> cannot be encoded by AddressEncoder instead of returning an empty array [].

[Q] How could I fix this error? What might be the reason for this? Is there any check mechanism for this exceptions error?

Most helpful comment

eth-abi expects addresses to be checksummed addresses. See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md

Your first address is a valid address, while the second is not:

>> from eth_utils import is_checksum_address
>>> is_checksum_address("0x4e4a0750350796164D8DefC442a712B7557BF282")
True
>>> is_checksum_address("0x4e4a0750350796164D8DefC442a712B7557BF281")
False
>>> 

>All comments

eth-abi expects addresses to be checksummed addresses. See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-55.md

Your first address is a valid address, while the second is not:

>> from eth_utils import is_checksum_address
>>> is_checksum_address("0x4e4a0750350796164D8DefC442a712B7557BF282")
True
>>> is_checksum_address("0x4e4a0750350796164D8DefC442a712B7557BF281")
False
>>> 
Was this page helpful?
0 / 5 - 0 ratings