Connect Python with bitbucket

Hey im trying to connect python with bitbucket but it keep saying that i need to create an app password although im using my app password, what am i doing wrong?

    url = 'https://bitbucket.org/api/2.0/user/'
    headers = {'Content-Type': 'application/json', "Authorization":"Bearer token"}
    r = requests.get(url, auth=('email', 'password'), headers=headers)
    print(r.status_code)
    print(r.text)

Welcome to the Atlassian developer community @anon44907228,

Although I’ve used requests quite often, I’m not sure which one wins between headers and auth, and you have both. Bitbucket Cloud expects basic auth, not a Bearer token. As such, drop the Authorization from headers and send it the way you are doing auth. Make sure to provide your app password for password.

not sure i understood, i need to change to r = requests.get(url, auth=(‘email’, ‘token’), headers=headers)? if im doing it, it repsoned 401 although the information are correct

Should be:

    headers = {'Content-Type': 'application/json'}

If im doing it and putting my account password in the requers.get i get “you’ll need to authenticate with a valid app password” and if im trying to put my app password in my password in the requers.get i get 401

@anon44907228,

A 401 is progress but I forgot the other trick to basic auth with Bitbucket Cloud: you must use your username, not your email address. You can find the username in your Bitbucket account settings. See my username in the image below.

Works! thank you very much!

1 Like