首页 > 解决方案 > 尝试使用 Bitbucket Cloud API 进行身份验证时获取 401 代码

问题描述

得到下面的问题,我可以获得存储库,但是当我尝试获取提交时,即它失败并且我得到 401。回购和工作区是私有的,所以第一个会失败我想如果代码有问题完全。最近有人做过吗?

baseUrlv2 = "https://bitbucket.org/api/2.0"
role = "contributor"
username = {bitbucket_username}
password = {bitbucket_app_password}

r = requests.get("{base}/repositories/{workspace}?role={role}".format(base=baseUrlv2, role=role),
    auth=(use
rname, password))

repos = r.json() 

while 'next' in repos:
    for repo in repos["values"]:
        commitLink = repo["links"]["commits"]["href"]
        repoSlug = repo["slug"]
        #the request below seems to be the issue :\
        r = requests.post((commitLink), auth=(username,password))
        
        c = r.json() #this is where it breaks

标签: pythonpython-requestsbitbucketbitbucket-cloud

解决方案


经过一堆试验和错误,其中 Atlassian 文档说使用您的 Bitbucket 用户名 + 应用程序密码.. 事实并非如此。您需要使用正常的电子邮件和密码才能实际使用 API。

Bitbucket 的 API 调用通常会出现一些奇怪的问题,但此问题已得到解决。


推荐阅读