Lomtrur
Lomtrur

Reputation: 1798

Python - curl request with requests, header not set correctly? (possible GitLab API issue)

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)

Upvotes: 5

Views: 7315

Answers (2)

Pippo
Pippo

Reputation: 925

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

"PRIVATE-TOKEN"

instead of

"PRIVATE_TOKEN"

Upvotes: 1

Reynard Asis
Reynard Asis

Reputation: 483

change PRIVATE_TOKEN to PRIVATE-TOKEN

Upvotes: 9

Related Questions