我正在尝试向Ropsten网络中的Etherscan API发送请求,但由于显示403错误,因此无法正常工作:
response = requests.get(
"https://api-ropsten.etherscan.io/api",
params={
"module": "account",
"action": "balance",
"address": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
"tag": "latest",
"apikey": "MyApiKey",
},
)
这是非常尴尬的,因为当我从邮递员那里用这个url做同样的事情时,它会起作用:
https://api-ropsten.etherscan.io/api?module=account&action=balance&address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae&tag=latest&apikey=MyApiKey
而且,当我对以太坊Mainnet执行相同的请求时,它也可以工作:
response = requests.get(
"https://api.etherscan.io/api",
params={
"module": "account",
"action": "balance",
"address": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
"tag": "latest",
"apikey": "MyApiKey",
},
)
我也在为同样的问题挣扎。对于其他正在挣扎的人,我找到了答案。本质上,Etherscan正在阻止不提供
User-agent
的请求,因此如果使用Python请求模块,请添加User-agent
头属性相关问题 更多 >
编程相关推荐