【问题标题】:OAuth2 authorization for API in PythonPython中API的OAuth2授权
【发布时间】:2018-07-18 00:54:11
【问题描述】:

我正在尝试通过 Manheim 公司使用 Python 3 对 API 使用 OAuth2 授权。

文档指出“‘客户凭证’和‘资源所有者’授权类型现在都受支持,请求令牌所需的更改在此处详细说明。”这是 API 的文档:http://developer.manheim.com/#/authentication

我使用以下链接作为指南,但无济于事: https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html#backend-application-flow

他们为我提供了客户端 ID 和客户端密码。我收到以下错误:

MissingTokenError: (missing_token) Missing access token parameter.

我试过了:

from oauthlib.oauth2 import BackendApplicationClient

client_id = 'my_id'
client_secret = 'my_secret'
token_url = 'https://sandbox.api.manheim.com/oauth2/token.oauth2'

client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=token_url, 
client_id=client_id,client_secret=client_secret)

我也试过这个:

from oauthlib.oauth2 import BackendApplicationClient
from requests.auth import HTTPBasicAuth

client_id = 'my_id'
client_secret = 'my_secret'
token_url = 'https://sandbox.api.manheim.com/oauth2/token.oauth2'

auth = HTTPBasicAuth(client_id, client_secret)
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=token_url, auth=auth)

我尝试了其他技术,但没有成功。我究竟做错了什么?我需要做什么才能访问 API?

感谢所有帮助!

【问题讨论】:

    标签: python api authentication oauth-2.0 credentials


    【解决方案1】:

    结果: 通过联系管理 API 的开发人员团队自己修复了它。我使用了错误的端点。

    我将 token_url 更改为以下内容:

    token_url = 'https://api.manheim.com/oauth2/token.oauth2'
    

    【讨论】:

      猜你喜欢
      • 2021-04-24
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      • 2018-07-14
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 2016-05-13
      相关资源
      最近更新 更多