Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Cant connect bitbucket using python stashy

Deleted user February 14, 2022

Hi im trying to build a script that return all of my project and repository from bitbucket using python and i dont get what im doing wrong.

import stashy

def getrepository():
 bitbucket = stashy.connect("https://bitbucket.org/dashboard/overview", 
 "username", "password")
 print(bitbucket.projects.list())

i get this error

stashy errors GenericException: Unknown error: 403(Forbidden)

1 answer

0 votes
Guilherme Franchi
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 15, 2022

Hello Eyal,

Welcome to the Atlassian Community.

Ok, so let me try to help you out with this. Stashy is a python client for the Atlassian Bitbucket Server (formerly known as Stash) REST API. Actually, you are trying to make API calls to the Bitbucket Cloud version, which is not supported by Stashy, in this case. So, it will not be able to make a connection to it, since the way that the REST apis are handled between Bitbucket Server and Bitbucket Cloud are, in some way, a little bit different.

In this case, you will need to make use of Bitbucket Cloud APIs and you may also need to import some of those atlassian's library to Python. Let me try to exemplify this for you:

There are some different ways of making that connection/authentication to bitbucket cloud, but I will use App Password. For this, you can create your App Password using the following steps:

  1. Log into bitbucket.org
  2. On the left side of your screen (left side bard), click on Your profile and settings Personal Settings
  3. Under ACCESS MANAGEMENT, click on App Passwords
  4. On that page, click on Create app password
  5. Under that new page, select all the Permissions that you will need and define a Label for your application, for example, python-app
  6. Once you hit Create, copy that app password, as you will use it for authentication

Ok, now, going back to Python, you will need to do the following (I will use python3 as an example):

from atlassian.bitbucket import Cloud

mybitbucketcloud = Cloud(
username="REPLACE_WITH_YOUR_USERNAME",
password="REPLACE_WITH_YOUR_APP_PASSWORD",
cloud=True)

# And, bellow, is just a way to iterate through your first project listed
projects = iter(mybitbucketcloud.workspaces.get("REPLACE_WITH_YOUR_WORKSPACE").projects.each())
# print the first one
print(next(projects))

 

For more additional information, you can check: Atlassian Python API 

 

Hope that it helps!

 

Regards,

Guilherme Franchi

Atlassian Support Engineer

 

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events