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)
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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.