我想通过Coinbase API中的Python请求模块提出一个简单的比特币价格请求
我可以通过以下URL获得在邮递员中工作的请求: https://api.coinbase.com/v2/prices/:BTC-USD/spot 包括两个标题: “api_密钥”:“xxx”, “a”:“BTC”
但是,以下Python代码会产生错误:
from datetime import datetime
import requests
# Make an API call to Coinbase and store the response
url = 'https://api.coinbase.com/v2/prices/:BTC-USD/spot'
headers = {
'Accept': "*/*",
"api_key": "xxx",
"a": "BTC"
}
r = requests.get(url, headers=headers)
print(f"Status code: {r.status_code}")
# Store API response in a variable.
response_dict = r.json()
print(response_dict)
这是返回的错误:
Status code: 404
{'errors': [{'id': 'not_found', 'message': 'Invalid base currency'}]}
感谢您的帮助。谢谢,
假设上面键入的是实际代码,则生成的错误是正确的。您要求的密码是:BTC而不是BTC。删除冒号,代码就可以运行了
相关问题 更多 >
编程相关推荐