XBRL API OAuth2 有问题

Having issue with XBRL API OAuth2

有人使用 XBRL API 处理财务数据 (https://xbrlus.github.io/xbrl-api/) 吗?我能够使用交互式演示但无法自行重新创建它并在访问 oauth2 时使用 python 请求库成功访问 API。

这就是我现在正在尝试的,returns 一个“无效请求”错误。感谢任何支持。

import requests

body_auth = {'username' : 'email@domain', 
            'client_id': 'generated from the XBRL API demo', 
            'client_secret' : 'generated from the XBRL API demo', 
            'password' : 'password', 
            'grant_type' : 'password'}

payload = urlencode(body_auth)
url = 'https://api.xbrl.us/oauth2/token'
headers = {"Content-Type": "application/x-www-form-urlencoded"}

res = requests.request("POST", url, data=payload, headers=headers)
auth_json = res.json()
auth_json

如果我修改你的代码添加:

from urllib.parse import urlencode

res.raise_for_status()

我得到:

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.xbrl.us/oauth2/token

我假设这就是您在说“无效请求”时看到的内容?

如果我随后使用自己的凭据更新 usernameclient_idclient_secretpassword,您的代码无需进一步修改即可工作。

奇怪的是,这会导致 400 错误而不是 401,但我推断问题出在您使用的凭据上,而不是代码上。