github get_organization 给出未找到错误 github.GithubException.UnknownObjectException: 404

github get_organization gives Not Found Error github.GithubException.UnknownObjectException: 404

我正在尝试筛选一些 github 回购协议。我有一份要筛选的组织列表。对于一些它工作正常,对于其他我得到 404 Not found 错误,即使它们确实存在:

github_api = Github(github_access_token)
print(github_api.get_organization('eosforce').get_repos())
 File "C:/Users/haase/Documents/VL/cryptodevel/create_repos.py", line 100, in <module>
    print(github_api.get_organization('eosforce').get_repos())
  File "C:\Users\haase\Documents\VL\pythonProject\lib\site-packages\github\MainClass.py", line 296, in get_organization
    headers, data = self.__requester.requestJsonAndCheck("GET", f"/orgs/{login}")
  File "C:\Users\haase\Documents\VL\pythonProject\lib\site-packages\github\Requester.py", line 353, in requestJsonAndCheck
    return self.__check(
  File "C:\Users\haase\Documents\VL\pythonProject\lib\site-packages\github\Requester.py", line 378, in __check
    raise self.__createException(status, responseHeaders, output)
github.GithubException.UnknownObjectException: 404 {"message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/orgs#get-an-organization"}

例如,这很好用:

print(github_api.get_organization('bitcoin').get_repos())

有人知道问题出在哪里吗?

这里的问题似乎是您想要获得回购协议的所有组织都不一定在 Github 上有一个 organization account

例如:

  • eosforce 有一个 Github user 帐户。
  • bitcoin 有一个 Github organization 帐户。

因此,您使用的端点:https://docs.github.com/en/rest/reference/orgs#get-an-organization 仅适用于组织,将 return 未找到具有用户帐户的组织的 http 状态(如 eosforce)。


实施的第一步应该是检查您要获取存储库的帐户是用户帐户还是组织帐户。

然后,要获取用户存储库,请使用:

https://docs.github.com/rest/reference/repos#list-repositories-for-a-user

要获取组织存储库,请使用:

https://docs.github.com/rest/reference/repos#list-organization-repositories

如有需要,请参阅 Github documentation about Repositories 了解有关如何使用这些端点的更多详细信息。