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?
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())