【问题标题】:Python How to Query API from Luno.com with HTTP AuthenticationPython 如何使用 HTTP 身份验证从 Luno.com 查询 API
【发布时间】:2021-06-02 13:49:58
【问题描述】:

我正在编写一个调用 Luno.com API 的 python 脚本。它将构成更大的 python 脚本的一部分(在单独的脚本中测试新的 API 调用),我已经成功调用了不同站点的 API,但是它不需要身份验证。 Luno 文档说它需要一个 API 密钥(我有),并在正常的 HTTP 身份验证中使用 id 和密钥作为用户名和密码,对 python 来说是新手,我用谷歌搜索了如何进行基本的 HTTP 身份验证并发现:

from requests.auth import HTTPBasicAuth
result = requests.get('url', auth=('username', 'password'))

我尝试过使用它,但无论我尝试什么似乎都无法正确使用,打印响应代码和 json 输出时出现以下错误:

<Response [404]>
{'error': 'Cannot find that market', 'error_code': 'ErrMarketNotFound', 'error_action': {}}

我将包含我的 python 脚本以及适用的 luno API 部分的链接。我要访问的 URL 是 https://api.luno.com/api/1/ticker ,用于获取货币对。

https://www.luno.com/en/developers/api

https://www.luno.com/en/developers/api#operation/getTicker

如果您不想点击链接,请查看屏幕截图:

Python 代码:

import json
import requests
from requests.auth import HTTPBasicAuth

urlLuno = 'https://api.luno.com/api/1/ticker'

statsAuthLuno = requests.get(urlLuno, auth=('idhere', 'secretkeyhere'))

print(statsAuthLuno)
print(statsAuthLuno.json())

【问题讨论】:

  • 顶帖,还没解决
  • 第二个凹凸

标签: python json api python-requests


【解决方案1】:

ticker API 不需要身份验证,但它需要市场对 as seen here

requests.get(urlLuno, params={"pair": "XBTMYR"})

应该会为您提供所需的详细信息。

或者你可以get all tickers

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-18
    • 2013-01-16
    • 2015-10-17
    • 2010-10-17
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多