0

I'm trying to connect to my bitbucket cloud account using python so that I can write a script to create a repository. However, when I am trying to connect using the below code, it keeps giving me a 401 login failed, despite me trying variations of username, email, password and app_password. Has anyone got an ideas as to why is isn't working?

----CODE BELOW----- def main(config): print("1")

headers = {"Content-Type": 'application/json', "Authorization": config["BITBUCKET"]["app_password"]}

auth = (config["BITBUCKET"]["username"], config["BITBUCKET"]["password"])

bb_base_url = f'https://api.bitbucket.org/2.0/repositories/'

print("2")

res = requests.get(bb_base_url, auth=auth, headers=headers)

print("3")
print(res.status_code)
print(res.text)
-----ERROR MESSAGE----
401
Login failed due to incorrect login credentials or method.
For information on authentication methods for Bitbucket Cloud APIs, visit:
    https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication
If you are unsure of which login details or login method to use, visit:
    https://support.atlassian.com/bitbucket-cloud/docs/log-into-or-connect-to-bitbucket-cloud/




...........................
Popchop3
  • 1
  • 2
  • You generate your token with `echo -n user-name:app_password | base64` and then you set it with `"Authorization": "Basic your_token"` – Randommm Nov 09 '22 at 08:16
  • Hi, thanks for your reply. I did already generate a token in bitbucket which I am passing through in the headers like below. I also tried without "Basic" and am still receiving the same 401 error headers = {"Content-Type": 'application/json', "Authorization": f'Basic {config["BITBUCKET"]["app_password"]}'} – Popchop3 Nov 09 '22 at 09:13
  • You can't just use the app password directly, you need to combine the info and convert it into base64 – Randommm Nov 10 '22 at 06:52
  • Hmm ok. How would I do that? – Popchop3 Nov 10 '22 at 21:35
  • `echo -n user-name:app_password | base64` – Randommm Nov 11 '22 at 05:04

0 Answers0