1

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
2
  • Does your token have access to the repository? Commented Aug 5, 2022 at 14:04
  • Yes i had, it was syntax problem. Commented Aug 8, 2022 at 9:41

1 Answer 1

2

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

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

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.