0

例如调用 gl = gitlab.Gitlab('http://192.168.2.175', private_token=run_args['my_token'])

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

产生无法作为 json 处理的输出。解析这些信息的过程是什么,或者我应该只使用标准的休息请求并放弃 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

4 回答 4

1

我相信您需要解决更多问题。我已经测试了以下设置,与您的设置类似,并且 gl.projects.list() 返回项目的 json 列表。

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 使用“幕后”请求https://github.com/python-gitlab/python-gitlab#requirements

于 2020-09-16T04:19:49.853 回答
0

另一种方法是将项目对象转换为字典

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"])
于 2021-08-05T13:05:33.393 回答
0

由于python-gitlab正在与您一起工作,因此requests您可以为其启用调试日志,在此处的另一个问题中进行了描述

只是回答这个很老的问题,因为我今天遇到了同样的问题:)

于 2022-01-26T11:42:48.643 回答
0

这是我正在寻找的答案。结果是一个类字典:projects = gl.projects.list(search='autobuild') for project in projects: for item in project。dict ['_attrs']:打印项目

这将生成与项目相关的变量列表。

于 2020-09-16T16:03:38.073 回答