2016-01-22 76 views
0

我正在尝试使用OAuth2将使用Python的授权令牌获取到REST API。我成功地使用CURL而不是使用python。我使用在以下文档中提供的例子: https://requests-oauthlib.readthedocs.org/en/latest/oauth2_workflow.htmlpython oauth2客户端尝试获取授权令牌时发生的问题

以下是我的代码:

#!/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 

我收到以下错误:

oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client) client_id value doesn't match HTTP Basic username value 

这是一个非常基本的API只需要client_id和client_credentials来获得授权令牌。

所有信息将不胜感激。

回答

0

的文件规定了以下项目:

client_id = r'your_client_id' 
client_secret = r'your_client_secret' 
redirect_uri = 'https://your.callback/uri' 

通过客户端密钥,你也许意味着客户端密钥?

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

尝试将其更改为上述并旋转。使用r''代替原始输入并给出令牌。

+0

谢谢!不幸的是,现在我得到了oauthlib.oauth2.rfc6749.errors.InvalidClientError:(invalid_client)客户端不能在每个请求中使用多个验证方法。 – user1658415

+0

您是否尝试连接到Microsoft Active Directory?如果没有特定的服务将会有所帮助,这样我就可以缩小正在发生的事情。 – earnshae

+0

我对OAUTH2的错误不是1我已经更新了答案以反映这一点 – earnshae

相关问题