【问题标题】:Getting Github Repo Filenames Using Python使用 Python 获取 Github Repo 文件名
【发布时间】:2018-03-31 03:03:17
【问题描述】:

如何在不登录用户帐户的情况下使用 Python/PyGithub 获取 Github 存储库中所有文件名的列表?

如果我只知道用户名而不知道他/她的密码,我该如何使用github.Github(self.login, self.password)

【问题讨论】:

  • 版主注意:这个问题在我看来非常清楚。

标签: python github pygithub


【解决方案1】:

source code shows,在获取 GitHub 对象时,您可以将密码保留为“None”。

    def __init__(self, login_or_token, password, base_url, timeout, client_id, client_secret, user_agent, per_page, api_preview):
        self._initializeDebugFeature()

        if password is not None:
            login = login_or_token
            if atLeastPython3:
                self.__authorizationHeader = "Basic " + base64.b64encode((login + ":" + password).encode("utf-8")).decode("utf-8").replace('\n', '')  # pragma no cover (Covered by Authentication.testAuthorizationHeaderWithXxx with Python 3)
            else:
                self.__authorizationHeader = "Basic " + base64.b64encode(login + ":" + password).replace('\n', '')
        elif login_or_token is not None:
            token = login_or_token
            self.__authorizationHeader = "token " + token
        else:
            self.__authorizationHeader = None

那是tested here:

def testLoggingWithoutAuthentication(self):
   self.assertEqual(github.Github().get_user("jacquev6").name, "Vincent Jacques")

从那里,您可以获得任何 public 存储库并列出他们的文件。

您只需要“登录”private repos。

【讨论】:

    猜你喜欢
    • 2023-02-20
    • 2022-11-25
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 2018-01-05
    • 1970-01-01
    相关资源
    最近更新 更多