I am facing difficulties connecting to the Bitbucket repo from python. I have come across few python modules which let us connect to the Bitbucket repository from python. I have tried 'Bitbucket-python' which enables me to connect to the Bitbucket repo but still i am not able to list out the repositories by using the same module.
Can you please suggest me any python module which i can use for the purpose?
I am stuck. Any help would be appreciated.
Thanks, Bikram
You can use stashy
module.
For example:
import stashy
bitbucket = stashy.connect("host", "username", "password")
projects = bitbucket.projects.list()
repos = bitbucket.repos.list()
for project in projects:
for repo in bitbucket.projects["%s" % (project["key"])].repos.list():
print(repo["name"])
print(repo["project"]['key'])
I would recommend using python's requests module and this url https://developer.atlassian.com/cloud/bitbucket/rest/api-group-repositories/#api-group-repositories as reference
To see if you have a connection maybe do something like this: The {workspace} is your workspaceid and the api key I generated under the security tab in you bitbucket account. Good luck!
import requests import json headers = { '{API key}': '{API secret}' 'Content-Type': 'application/json' } #Get repo list url = "https://api.bitbucket.org/2.0/repositories/{workspace}" response = requests.request("GET", url, headers=headers) print(response) # 200 reponse means there is a connection #or if you have repos try this to print them print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.