0

for instance the call gl = gitlab.Gitlab('http://192.168.2.175', private_token=run_args['my_token'])

projects = gl.projects.list()
for project in projects:
    print(project)

produces output that cannot be processed as json. What is the process for parsing this information or should i just used standard rest requests and abandon python-gitlab?

<class 'gitlab.v4.objects.Project'> => {u'lfs_enabled': True, u'forks_count': 0, u'autoclose_referenced_issues': True, ... u'avatar_url': None, u'auto_cancel_pending_pipelines': u'enabled', u'jobs_enabled': True}

4 Answers4

2

I believe you need to troubleshoot more. I have tested out the following set up, which is similar to yours, and gl.projects.list() returns a json list of the projects.

gl = gitlab.Gitlab('https://gitlab.com/', ACCESS_TOKEN)

def get_projects():
    projects = gl.projects.list(owned=True)
    for project in projects:
        print(project.name)

(python-gitlab uses requests "under the hood" https://github.com/python-gitlab/python-gitlab#requirements)

amBear
  • 900
  • 6
  • 7
0

Here is the answer for which I was looking. The results are a class dictionary: projects = gl.projects.list(search='autobuild') for project in projects: for item in project.dict['_attrs']: print item

This produces the list of variables pertinent to the project.

0

Another approach would be, convert the project object into a dictionary.

gl = gitlab.Gitlab('https://gitlab.com/', ACCESS_TOKEN)

def get_projects():
    projects = gl.projects.list(owned=True)
    for project in projects:
        project = project.attributes
        print(project["name"])
hitesh bedre
  • 459
  • 2
  • 11
0

Since python-gitlab is working under the hood with requests you can just enable debug logs for it, described in another question here

Just answering to this quite old question, because I had the same problem today :)

c0r3x
  • 1