Skip to content

Instantly share code, notes, and snippets.

@epicserve
Created June 21, 2019 16:36
Show Gist options
  • Save epicserve/403e844e2f2d645a37a554bb5484d011 to your computer and use it in GitHub Desktop.
Save epicserve/403e844e2f2d645a37a554bb5484d011 to your computer and use it in GitHub Desktop.
import os
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
client_id = os.environ['BITBUCKET_KEY']
client_secret = os.environ['BITBUCKET_SECRET']
username = os.environ['BITBUCKET_USERNAME']
password = os.environ['BITBUCKET_PASSWORD']
token_url = 'https://bitbucket.org/site/oauth2/access_token'
"""
The following code results in the error:
Traceback (most recent call last):
File "bitbucket.py", line 16, in <module>
client_secret=client_secret
File "/Users/brento/.virtualenvs/pears/lib/python3.6/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/brento/.virtualenvs/pears/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 411, in parse_request_body_response
self.token = parse_token_response(body, scope=scope)
File "/Users/brento/.virtualenvs/pears/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 379, in parse_token_response
validate_token_parameters(params)
File "/Users/brento/.virtualenvs/pears/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 386, in validate_token_parameters
raise_from_error(params.get('error'), params)
File "/Users/brento/.virtualenvs/pears/lib/python3.6/site-packages/oauthlib/oauth2/rfc6749/errors.py", line 415, in raise_from_error
raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidClientIdError: (invalid_request) No callback uri defined for the OAuth client.
"""
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
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment