想通过Coinbase API中的Python请求模块获得简单的比特币报价吗

2024-04-19 20:55:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想通过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'}]}

感谢您的帮助。谢谢,


Tags: httpscomapiresponsecodev2xxxheaders