Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python api request to gitlab unexpectedly returns empty result

import requests

response = requests.get("https://gitlab.com/api/v4/users/ahmed_sh/projects")
print(response.status_code)  # 200
print(response.text)  # []
print(response.json()) # []

I’m trying to get a list of my GitLab repo projects using python API, but the outputs are nothing! Although, when I use the browser, I got a non-empty response. How can I solve this problem?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is because you don’t have any public projects in your user namespace. If you want to see your private projects in your namespace, you’ll need to authenticate with the API by passing a personal access token in the PRIVATE-TOKEN header.

Note, this also won’t show projects you work on in other namespaces.

headers = {'PRIVATE-TOKEN': 'Your API key here!'}
resp = requests.get('https://gitlab.com/api/v4/users/ahmed_sh/projects', headers=headers)
print(resp.json())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading