Web3js

web3.py ( web3.exceptions.CannotHandleRequest: 發出請求時無法發現提供者: method:eth_call ) –help

  • June 6, 2021
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)

本契約的功能:

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'])

錯誤來自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']

有人可以解釋我在使用這些參數時遇到的錯誤web3.py嗎?

我進口不好:

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

固定進口:

from web3 import Web3

我有同樣的問題。有沒有人弄清楚是什麼原因造成的。我已經使用了上面建議的導入,但仍然出現錯誤:

from web3 import Web3

引用自:https://ethereum.stackexchange.com/questions/87982