【问题标题】:API requests always return 404 no matter what无论如何,API 请求总是返回 404
【发布时间】:2021-05-17 16:07:39
【问题描述】:

我正在尝试自动化我之前手动执行的交易策略。这需要通过 API 与我的代理进行通信。我通过 HTTP 基本身份验证进行授权。为了测试,我尝试发出 API 请求以获取有关我帐户中资金的信息。

起初,我收到了401 的回复,结果发现我使用了错误的身份信息。

在我解决了这个问题后,我发出的所有 API 请求都会给我404 响应。

一个例子

import requests
from requests.auth import HTTPBasicAuth

response = requests.get("https://api-demo.exante.eu/md/{version}/accounts", auth=HTTPBasicAuth
    ('name', 'pass'))

print(response)

之后,我在网上试了一些代码,看看有没有其他问题。我试过这个

https://gist.github.com/rshrc/127ba2c20df74263d71bc5a5595c8969

这也给了我404。

链接到我的代理 API 文档:

https://api-live.exante.eu/api-docs/#section/API-versions

有谁知道问题出在哪里?方向会很有帮助。谢谢!

【问题讨论】:

  • 您是否已将{version} 替换为适当的值。应该是“2.0”或“3.0”。

标签: python api http-status-code-404 algorithmic-trading


【解决方案1】:

您似乎没有传递带有 {version} 变量的版本。不要忘记在 URL 字符串之前使用 f 格式化 URL 字符串。这应该有效:

import requests
from requests.auth import HTTPBasicAuth

version = "3.0"
response = requests.get(f"https://api-demo.exante.eu/md/{version}/accounts", auth=HTTPBasicAuth
    ('name', 'pass'))

print(response)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 2023-03-05
    • 2017-12-07
    相关资源
    最近更新 更多