Search code examples
python-3.xgitlabgitlab-api

GitlabParsingError when accessing a project with GitLab API with Python


I try to access a project on a private GitLab instance (please take a look at the screenshot for the version numbers) by using the python-gitlab module.

enter image description here

I have created an access token with all permissions over the web UI of the GitLab repository and copied this token into my Python code:

import gitlab

gl = gitlab.Gitlab("https://MyGit.com/.../MyProject", "k1WMD-fE5nY5V-RWFb-G")
print(gl.projects.list())

Python throws the following error during the execution

Exception: GitlabParsingError       (note: full exception trace is shown but execution is paused at: <module>)
Failed to parse the server message

During handling of the above exception, another exception occurred:


The above exception was the direct cause of the following exception:

  File ".../app.py", line 226, in <module> (Current frame)
    print(gl.projects.list())

Solution

  • The first argument to gitlab.Gitlab() is the base URL of the instance not the full path to your project. e.g. https://gitlab.example.com. You should also use the keyword private_token

    So, unless your instance lives at a relative path, you should have:

    gl = gitlab.Gitlab('https://MyGit.com', private_token='your API key')