Python 中 API 的 OAuth2 授权

OAuth2 authorization for API in Python

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

文档说明 "The 'Client Credentials' and 'Resource Owner' grant types are both supported now and required changes to request a token are detailed here." 这是 API 的文档:http://developer.manheim.com/#/authentication

我使用了以下 link 作为指南,但无济于事: 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?

感谢所有帮助!

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

我将 token_url 更改为以下内容:

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