python - OAuth2 InvalidScopeError in Backend Application flow -
i trying implement backend application flow access token datahug api (following instructions in https://api.datahug.com/#gettingstarted).
from oauthlib.oauth2 import backendapplicationclient requests_oauthlib import oauth2session def get_access_token(): token_url = 'https://apps.datahug.com/identity/connect/token' client_id = client_id client_secret = client_secret scope = 'datahug_api' client = backendapplicationclient(client_id=client_id) client.prepare_request_body(scope=[scope]) oauth = oauth2session(client=client) token = oauth.fetch_token(token_url=token_url, client_id=client_id, client_secret=client_secret) return token if __name__ == '__main__': token = get_access_token() print(token)
when running code i'm getting invalidscopeerror, namely
user:dh user$ python so_test.py traceback (most recent call last): file "so_test.py", line 21, in <module> token = get_access_token() file "so_test.py", line 17, in get_access_token client_secret=client_secret) file "/users/user/anaconda3/lib/python3.5/site-packages/requests_oauthlib/oauth2_session.py", line 244, in fetch_token self._client.parse_request_body_response(r.text, scope=self.scope) file "/users/user/anaconda3/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 409, in parse_request_body_response self.token = parse_token_response(body, scope=scope) file "/users/user/anaconda3/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 376, in parse_token_response validate_token_parameters(params) file "/users/user/anaconda3/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 383, in validate_token_parameters raise_from_error(params.get('error'), params) file "/users/user/anaconda3/lib/python3.5/site-packages/oauthlib/oauth2/rfc6749/errors.py", line 325, in raise_from_error raise cls(**kwargs) oauthlib.oauth2.rfc6749.errors.invalidscopeerror: (invalid_scope)
it seems problem in value scope='datahug_api'
, value suggested in datahug api. suggestions on how solve appreciated.
Comments
Post a Comment