pythonpython-requestsgitlab

Why does my Gitlab Requests always return a Error 400


When I call the Gitlab API, searching for a User named Ed I get this Error.

I have tried curling the API outside of Python and I do not receive this error.

import requests

r = requests.post("https://git.deploys.io/api/v4/users?username=Ed", headers={"PRIVATE-TOKEN":"Removed Token"})
print(r)

It should return [] as if no user was found or it should return a JSON with the Users information.


Solution

  • Check out what is returned: the GitLab Users API page does mention:

    If an error occurs a 400 Bad Request is returned with a message explaining the error.

    That, or it is a server-side issue, as in gitlab-com/support-forum issue 2720

    The 400 errors were caused by a server side check that required a User-Agent header to be provided.
    That's why only particular clients were affected.