【发布时间】:2021-10-09 20:49:56
【问题描述】:
我想通过来自 Coinbase API 的 Python 请求模块发出一个简单的比特币价格请求
我可以在 Postman 中点击此 URL 来获取工作请求: https://api.coinbase.com/v2/prices/:BTC-USD/spot 包括两个标题: "api_key": "xxx", "a": "比特币"
但是以下 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'}]}
感谢任何帮助。谢谢,
【问题讨论】:
-
您从哪里获得有关标题和网址的信息?它甚至与docs 中描述的内容都不接近。
标签: python api coinbase-api