Python – working with GitLab API 403 Forbidden Error

Question:

I am trying to make POST request to GitLab and make file with my Python code. Url is fine I tested it in Postman and request worked fine and made file in repo.

But when i tried to use Python it didn’t work.

Python code:

req = requests.post("https://gitlab.com/api/v4/projects/38163703/repository/files/python_code_test", 
                data={"start_branch": "main",
                "branch": "main",
                "content": "test python",
                "commit_message": "python test"}, 
                headers = {"PRIVATE_TOKEN": "<token>"})

print(req.status_code, req.reason)

Error:

403 Forbidden
Asked By: wondergrandma

||

Answers:

It’s supposed to be PRIVATE-TOKEN and not PRIVATE_TOKEN in data.

Answered By: wondergrandma
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.