首页 > 解决方案 > github get_organization 给出 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())

有谁知道问题出在哪里?

标签: pythongithub-api

解决方案


似乎这里的问题是,您想要获得 repos 的所有组织都不必organization account在 Github 上拥有。

例如:

  • eosforce有一个 Githubuser帐户。
  • 比特币有一个 Githuborganization帐户。

因此,您使用的端点:https://docs.github.com/en/rest/reference/orgs#get-an-organization仅适用于组织,将为具有用户帐户的组织返回未找到的 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 文档。


推荐阅读