2
proveedores= ['https://mainnet.infura.io/v3/KEY_KEY','https://ropsten.infura.io/v3/KEY_KEY']

from web3 import Web3 , HTTPProvider, IPCProvider, WebsocketProvider
from web3.auto import w3

web3= Web3(Web3.HTTPProvider(proveedores[0], request_kwargs={'timeout': 60}))


textABI= '[{"inputs":[{"intern...'

abij= json.loads(textABI)
dress= {'aDAI': {'address': '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d', 'decimals': 18}}


contract1 = w3.eth.contract(address= "0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d", abi=abij)


# THIS FUNCTIONS ERRORS
buildContract= contract1.functions.name().call()
print(buildContract)

# THIS FUNCTION ERRORS
buildContract= contract1.functions.symbol().call()
print(buildContract)

Functions of this contract:

dict_keys(['abi', 'web3', 'address', '_functions', 'UINT_MAX_VALUE', 'allowInterestRedirectionTo', 'allowance', 'approve', 'balanceOf', 'burnOnLiquidation', 'decimals', 'decreaseAllowance', 'getInterestRedirectionAddress', 'getRedirectedBalance', 'getUserIndex', 'increaseAllowance', 'isTransferAllowed', 'mintOnDeposit', 'name', 'principalBalanceOf', 'redeem', 'redirectInterestStream', 'redirectInterestStreamOf', 'symbol', 'totalSupply', 'transfer', 'transferFrom', 'transferOnLiquidation', 'underlyingAssetAddress'])

Error from contract1:

Traceback (most recent call last):
  File "PATH/proyect7.py", line 82, in <module>
    buildContract= contract1.functions.symbol().call()
  File "PATH\env\lib\site-packages\web3\contract.py", line 964, in call
    **self.kwargs
  File "PATH\env\lib\site-packages\web3\contract.py", line 1499, in call_contract_function
    return_data = web3.eth.call(call_transaction, block_identifier=block_id)
  File "PATH\env\lib\site-packages\eth_utils\functional.py", line 45, in inner
    return callback(fn(*args, **kwargs))
  File "PATH\env\lib\site-packages\web3\eth.py", line 434, in call
    [transaction, block_identifier],
  File "PATH\env\lib\site-packages\web3\manager.py", line 149, in request_blocking
    response = self._make_request(method, params)
  File "PATH\env\lib\site-packages\web3\manager.py", line 128, in _make_request
    return request_func(method, params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
    return self.func(*args, **kwargs)
  File "PATH\env\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
    response = make_request(method, params)
  File "PATH\env\lib\site-packages\web3\middleware\gas_price_strategy.py", line 34, in middleware
    return make_request(method, params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
    return self.func(*args, **kwargs)
  File "PATH\env\lib\site-packages\web3\middleware\formatting.py", line 74, in apply_formatters
    response = make_request(method, formatted_params)
  File "PATH\env\lib\site-packages\web3\middleware\attrdict.py", line 33, in middleware
    response = make_request(method, params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
    return self.func(*args, **kwargs)
  File "PATH\env\lib\site-packages\web3\middleware\formatting.py", line 74, in apply_formatters
    response = make_request(method, formatted_params)
  File "PATH\env\lib\site-packages\web3\middleware\normalize_errors.py", line 25, in middleware
    result = make_request(method, params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
    return self.func(*args, **kwargs)
  File "PATH\env\lib\site-packages\web3\middleware\formatting.py", line 74, in apply_formatters
    response = make_request(method, formatted_params)
  File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
    return self.func(*args, **kwargs)
  File "PATH\env\lib\site-packages\web3\middleware\formatting.py", line 74, in apply_formatters
    response = make_request(method, formatted_params)
  File "PATH\env\lib\site-packages\web3\providers\auto.py", line 94, in make_request
    return self._proxy_request(method, params)
  File "PATH\env\lib\site-packages\web3\providers\auto.py", line 111, in _proxy_request
    params))
web3.exceptions.CannotHandleRequest: Could not discover provider while making request: method:eth_call
params:[{'to': '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d', 'data': '0x95d89b41'}, 'latest']

Can someone explaine the error that I get when using these parameters with web3.py?

1

3 Answers 3

2

I had bad imports:

from web3 import Web3, HTTPProvider, IPCProvider, WebsocketProvider
from web3.auto import w3

Fixed imports:

from web3 import Web3
3
  • Can you please explain how exactly this solves your problem?
    – tripleee
    Commented Oct 7, 2020 at 4:19
  • bad import: from web3 import Web3 , HTTPProvider, IPCProvider, WebsocketProvider from web3.auto import w3 |||||| good import: from web3 import Web3 Commented Oct 7, 2020 at 9:11
  • Please update your answer instead. I have submitted an edit suggestion; can you please accept it? Or of course override it if you want to phrase it yourself.
    – tripleee
    Commented Oct 7, 2020 at 9:16
2

I had the same problem. Has anyone figured out what is causing this. I have used the imports suggested above but still get the error:

from web3 import Web3
0
0

I had a similar problem, the issue is your Web3 object does not recognize the provider. It gets resloved with this:

from web3 import Web3


my_provider = Web3.HTTPProvider(<http rpc (infura | alchemy)>)
w3 = Web3(my_provider)

nonce = w3.eth.get_transaction_count(public_key)

Basically any method that needs to read data off of the blockchain will require a provider.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.