5

I am trying to use the Gitlab API to make an issue from Python.

The following curl request works (tested and confirmed):

curl --request POST --header "PRIVATE-TOKEN: <my token>" https://gitlab.com/api/v3/projects/<my project id>/issues?title=Issues%20with%20auth&labels=bug

My Python code:

import requests
r = requests.post("https://gitlab.com/api/v3/projects/2674887/issues", data={
        "title":issueform.instance.title,
        "description":issueform.instance.description
        },
                    headers={"PRIVATE_TOKEN":"<token>"})
    print(r.status_code, r.reason)

I get: 401 Unauthorized

Am I doing something wrong in my POST request or is this an issue with GitLab rejecting doing it this way possibly?

The relevant part from the API: http://docs.gitlab.com/ee/api/issues.html#new-issue

EDIT:

Forgot to mention, ignore the issueform.instance stuff, they are just Strings (it is a Django project and I omitted the form stuff because it shouldn't be relevant)

1
  • CURL with subprocess.Popen and multiple params (title=IssueABC&labels=bug)wasn't working, probably something weird with the string encoding I guess... but dropping in requests is working great! Commented Jun 12, 2019 at 23:43

2 Answers 2

9

change PRIVATE_TOKEN to PRIVATE-TOKEN

Sign up to request clarification or add additional context in comments.

1 Comment

@Lomtrur well, we commit this kind of mistake
1

Maybe it just a typo? could you try the below?

"PRIVATE-TOKEN"

instead of

"PRIVATE_TOKEN"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.