简体   繁体   English

通过Python请求将问题发布到Bitbucket

[英]Post issues to Bitbucket via Python requests

I'm trying to post issues to bitbucket via their api. 我正试图通过他们的api向bitbucket发布问题。 If I understand correctly it seems I can go the basic authentication route rather than OAuth. 如果我理解正确,我似乎可以使用基本身份验证路由而不是OAuth。 When making the request, though, when print(r.status_code) runs I'm getting a 400 code back in the terminal. 但是,在发出请求时,当print(r.status_code)运行时,我在终端中获得了400代码。 The problem seems to be in either the json (which I doubt) or the authentication. 问题似乎是在json(我怀疑)或身份验证。

I'm running this in a django project and my code is as follows: 我在django项目中运行它,我的代码如下:

views.py views.py

if request.method == "POST":
    getUser = request.user
    form = IssueForm(request.POST)

    if form.is_valid():

        data = {"priority": "major", "title": "title", "kind": "bug", "content": "content"} 

        headers = {'Content-Type': 'application/json',}
        r = requests.post('https://api.bitbucket.org/1.0/repositories/{my_username}/{my_repo}/issues/', headers=headers, json=data, auth=({username},{password}))
        print(r.status_code)

        return HttpResponseRedirect("/main/")

    else:
        form = IssueForm()


    context = {
        "form": form,
    }

    return render(request, "issue_form.html", context)

Possibly basic authentication is not allowed for posting issues and instead OAuth is necessary? 发布问题可能不允许进行基本身份验证,而OAuth是必要的吗? However, I have not found any documentation that has indicated as such. 但是,我没有找到任何已经指明的文件。 Or perhaps there is a way to go about implementing OAuth1 via python requests in Django? 或者也许有办法在Django中通过python请求实现OAuth1?

Username, repo, and password are filled in accordingly. 相应地填写用户名,回购和密码。 Any help would be much appreciated. 任何帮助将非常感激。

EDIT 编辑

Took the auth=({username},{password}) out and got a 401 as opposed to a 400 error with them in. Seems to be a problem with the data but I'm not quite sure what's wrong with the formatting of the data. 取出auth =({username},{password})并获得401而不是400错误。它们似乎是数据的问题,但我不太确定格式化的问题是什么数据。 Any further help is appreciated. 任何进一步的帮助表示赞赏

Reading always helps, kids. 孩子,阅读总是有帮助的。 I was able to just install BitBucket-API and use it along with the help of this documentation to post my issues. 我能够安装BitBucket-API并在本文档的帮助下使用它来发布我的问题。

https://media.readthedocs.org/pdf/bitbucket-api/latest/bitbucket-api.pdf https://media.readthedocs.org/pdf/bitbucket-api/latest/bitbucket-api.pdf

code ended up looking like: bb = Bitbucket('username', 'password', repo_name_or_slug="REPOSLUG") success, result = bb.issue.create( title=u'title', content=u'content', responsible=bb.username, status=u'new', kind=u'kind') 代码最终看起来像: bb = Bitbucket('username', 'password', repo_name_or_slug="REPOSLUG") success, result = bb.issue.create( title=u'title', content=u'content', responsible=bb.username, status=u'new', kind=u'kind')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM