【问题标题】:Want to get a simple Bitcoin price quote via Python requests module from Coinbase API想通过 Coinbase API 的 Python requests 模块获取简单的比特币报价
【发布时间】: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


【解决方案1】:

假设您在上面键入的是您的实际代码,那么生成的错误是正确的。您要求提供加密代码:BTC 而不是 BTC。删除冒号,您的代码应该可以工作。

【讨论】:

    猜你喜欢
    • 2021-09-15
    • 1970-01-01
    • 2020-09-29
    • 2021-08-02
    • 2022-01-14
    • 2014-11-26
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多