3

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())
Kampi
  • 1,798
  • 18
  • 26

1 Answers1

1

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')
sytech
  • 29,298
  • 3
  • 45
  • 86
  • So it is not possible to limit the view of the API to one specific project by using a project-specific URL and token? I tried it a few seconds ago by using the instance URL and a private token for one specific project. But I can read out a lot of IDs `[, , , , , , , ...` – Kampi Nov 08 '21 at 07:39
  • You can use a project-scoped token, but you will always initialize the `gl` object the same way with the base URL. [Project-scoped tokens](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html) are just like any other token, they just belong to a bot user who can only be granted write access to the specific project for which the token was created. But that token will also potentially have access to read other public/internal projects. @Kampi – sytech Nov 08 '21 at 19:29