【问题标题】:How to retrieve the star counts in GitLab Python API?如何在 GitLab Python API 中检索星数?
【发布时间】:2022-11-04 12:02:39
【问题描述】:

我尝试使用其Python client 请求 GitLab 中公共软件存储库的星数和提交数。但是,如果执行以下脚本,我会不断收到GitlabHttpError 503

import gitlab
import requests

url = 'https://gitlab.com/juliensimon/huggingface-demos'
private_token = 'xxxxxxxx'

gl = gitlab.Gitlab(url, private_token=private_token)
all_projects = gl.projects.list(all=True)

我阅读了之前的帖子,但没有一篇对我有用:[1][2][3]。人们提到:

  1. 稍后重试通常有效[I tried in different periods but still got the same error.]
  2. no_proxy [Not sure what it means for me? I do not set the proxy explicitly.] 设置环境变量

【问题讨论】:

    标签: gitlab python-gitlab


    【解决方案1】:

    503 响应告诉您一些事情 - 您的基本 URL 已关闭。您只需要提供基本 GitLab URL,以便客户端针对其 api/v4/ 端点发出请求。

    要么仅使用https://gitlab.com,以便客户端正确调用https://gitlab.com/api/v4 端点(而不是像现在那样尝试https://gitlab.com/juliensimon/huggingface-demos/api/v4),或者如果您使用的是python-gitlab 3.0,则在使用GitLab.com 时完全跳过它。 0 或更高版本。

    # Explicit gitlab.com
    url = 'https://gitlab.com'
    
    gl = gitlab.Gitlab(url, private_token=private_token)
    
    # Or just use the default for GitLab.com (python-gitlab 3.0.0+ required)
    gl = gitlab.Gitlab(private_token=private_token)
    

    编辑:最初的问题是关于 503,但对我的回答的评论是关于如何获取项目详细信息的后续行动。这是完整的 sn-p,它也从环境中获取令牌:

    import os
    import gitlab
    
    private_token = os.getenv("GITLAB_PRIVATE_TOKEN")
    
    gl = gitlab.Gitlab(private_token=private_token)
    project = gl.projects.get("juliensimon/huggingface-demos")
    
    print(project.forks_count)
    print(project.star_count)
    

    【讨论】:

    • 如何检索公共存储库的元数据,例如 star_count 和 fork_count?例如:gitlab.com/juliensimon/huggingface-demos
    • @JimmyZhao 这感觉像是一个后续问题,但我已经编辑了我的答案以添加它。看上面。
    • 非常感谢,这完全回答了我的帖子!
    猜你喜欢
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    • 2018-12-31
    • 2018-02-12
    相关资源
    最近更新 更多