我正在尝试向Ropsten网络中的Etherscan API发送请求,但它无法工作,因为它显示403错误:
response = requests.get(
"https://api-ropsten.etherscan.io/api",
params={
"module": "account",
"action": "balance",
"address": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
"tag": "latest",
"apikey": "MyApiKey",
},
)这是非常笨拙的,因为当我在Postman中对这个url执行相同的操作时,它可以工作:
https://api-ropsten.etherscan.io/api?module=account&action=balance&address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae&tag=latest&apikey=MyApiKey而且,当我向Ethereum发出同样的请求时,它也能正常工作:
response = requests.get(
"https://api.etherscan.io/api",
params={
"module": "account",
"action": "balance",
"address": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
"tag": "latest",
"apikey": "MyApiKey",
},
)发布于 2021-10-08 08:52:25
我也在为同样的问题苦苦挣扎。对于其他正在苦苦挣扎的人,我找到了here的答案。本质上,Etherscan阻塞的是不提供User-agent的请求,因此如果使用User-agent请求模块,则添加Python header属性。
response = requests.get(
"https://api-ropsten.etherscan.io/api",
params={
"module": "account",
"action": "balance",
"address": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
"tag": "latest",
"apikey": "API_KEY",
},
headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, '
'like Gecko) Chrome/50.0.2661.102 Safari/537.36'})https://stackoverflow.com/questions/69312369
复制相似问题