这是我连接到 Box 的代码,但我无法让 box_storage.get_auth_session(data=data) 工作。从 rauth 导入 OAuth2Service
box_storage = OAuth2Service(
name='Box',
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
authorize_url='https://www.box.com/api/oauth2/authorize',
access_token_url='https://www.box.com/api/oauth2/token',
base_url='https://www.box.com/'
)
redirect_uri = 'http://127.0.0.1'
params = {
'redirect_uri': redirect_uri,
'response_type': 'code',
'state': 'good'
}
url = box_storage.get_authorize_url(**params)
data = {'code': 'foobar',
'grant_type': 'authorization_code',
'redirect_uri': redirect_uri}
session = box_storage.get_auth_session(data=data)
这是我得到的错误:
Traceback (most recent call last):
File "C:\Users\rushd\Documents\Aptana Studio 3 Workspace\practice\box.py", line 24, in <module>
session = box_storage.get_auth_session(data=data)
File "C:\Users\rushd\Envs\practice\lib\site-packages\rauth\service.py", line 533, in get_auth_session
return self.get_session(self.get_access_token(method, **kwargs))
File "C:\Users\rushd\Envs\practice\lib\site-packages\rauth\service.py", line 519, in get_access_token
access_token, = process_token_request(r, decoder, key)
File "C:\Users\rushd\Envs\practice\lib\site-packages\rauth\service.py", line 24, in process_token_request
raise KeyError(PROCESS_TOKEN_ERROR.format(key=bad_key, raw=r.content))
KeyError: 'Decoder failed to handle access_token with data as returned by provider. A different decoder may be needed. Provider returned: {"error":"invalid_grant","error_description":"Auth code doesn\'t exist or is invalid for the client"}'
当我调用 get_auth_session 时,我很难弄清楚为什么会出现这个错误。会是什么?