[英]Want to get a simple Bitcoin price quote via Python requests module from Coinbase API
I want to make a simple Bitcoin Price request via Python requests module from Coinbase API我想通过来自 Coinbase API 的 Python 请求模块发出一个简单的比特币价格请求
I can get the request to work in Postman hitting this URL: https://api.coinbase.com/v2/prices/:BTC-USD/spot Included two headers: "api_key": "xxx", "a": "BTC"我可以通过点击这个 URL 获得在 Postman 工作的请求: https ://api.coinbase.com/v2/prices/:BTC-USD/spot 包括两个标题:“api_key”:“xxx”,“a”:“比特币”
However the following Python code produces and error:但是,以下 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)
This is the error returned:这是返回的错误:
Status code: 404
{'errors': [{'id': 'not_found', 'message': 'Invalid base currency'}]}
Any help is appreciated.任何帮助表示赞赏。 Thank you,
谢谢,
Assuming what you typed above is your actual code, then the error generated is correct.假设您在上面输入的是您的实际代码,那么生成的错误是正确的。 You have asked for crypto code :BTC and not BTC.
您要求提供加密代码:BTC 而不是 BTC。 Remove the colon and your code should work.
删除冒号,您的代码应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.