Etherscan API 在 Ropsten 网络中禁止请求 403
Etherscan API request 403 forbidden in Ropsten network
我正在尝试向 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 从 Postman 做同样的事情时,它起作用了:
https://api-ropsten.etherscan.io/api?module=account&action=balance&address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae&tag=latest&apikey=MyApiKey
而且,当我向以太坊主网发出相同的请求时,它也能正常工作:
response = requests.get(
"https://api.etherscan.io/api",
params={
"module": "account",
"action": "balance",
"address": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
"tag": "latest",
"apikey": "MyApiKey",
},
)
我也在为同样的问题苦苦挣扎。对于其他正在挣扎的人,我找到了答案 here。本质上,Etherscan 会阻止不提供 User-agent
的请求,因此如果使用 Python 请求模块,请添加 User-agent
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'})
我正在尝试向 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 从 Postman 做同样的事情时,它起作用了:
https://api-ropsten.etherscan.io/api?module=account&action=balance&address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae&tag=latest&apikey=MyApiKey
而且,当我向以太坊主网发出相同的请求时,它也能正常工作:
response = requests.get(
"https://api.etherscan.io/api",
params={
"module": "account",
"action": "balance",
"address": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
"tag": "latest",
"apikey": "MyApiKey",
},
)
我也在为同样的问题苦苦挣扎。对于其他正在挣扎的人,我找到了答案 here。本质上,Etherscan 会阻止不提供 User-agent
的请求,因此如果使用 Python 请求模块,请添加 User-agent
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'})