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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,459,361
Community Members
 
Community Events
176
Community Groups

Cant connect bitbucket using python stashy

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

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

Atlassian Community Events