python oauth2客户端尝试获取授权令牌时出现问题

ohm*_*hmr 5 python rest client access-token oauth-2.0

我正在尝试使用 OAuth2 通过 Python 获取 REST API 的授权令牌。我使用 CURL 成功做到了这一点,但使用 python 却失败了。我正在使用以下文档中提供的示例: https://requests-oauthlib.readthedocs.org/en/latest/oauth2_workflow.html

以下是我的代码:

#!/usr/bin/python

import requests
import requests_oauthlib
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient

client_id = 'AAAAAA'
client_secret = 'BBBBBB'

client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='https://example.com/as/token.oauth2', client_id=client_id, client_secret=client_secret)

print token
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client)   client_id value doesn't match HTTP Basic username value
Run Code Online (Sandbox Code Playgroud)

这是一个非常基本的 API,只需要 client_id 和 client_credentials 即可获取授权令牌。

所有信息将不胜感激。

ear*_*hae 1

该文档指定了以下项目:

client_id = r'your_client_id'
client_secret = r'your_client_secret'
redirect_uri = 'https://your.callback/uri'
Run Code Online (Sandbox Code Playgroud)

您所说的客户端密钥可能是指客户端密钥吗?

token = oauth.fetch_token(token_url='https://example.com/as/token.oauth2', client_id=client_id, client_secret=client_secret)
Run Code Online (Sandbox Code Playgroud)

尝试将其更改为上面的内容并试一试。使用 r'' 作为原始输入并给出标记。