Emil Haas
Emil Haas

Reputation: 734

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

I am trying to screen some github repos. I have a list of organizations that I want to screen. For some it is working fine, for other I am getting 404 Not found error even though they actually exist:

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"}

For example, this works fine:

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

Does anybody have any idea where can be the problem?

Upvotes: 1

Views: 1160

Answers (1)

GuiFalourd
GuiFalourd

Reputation: 22950

It seems that the problem here is that all organizations you want to get repos don't necessary have an organization account on Github.

For example:

  • eosforce has a Github user account.
  • bitcoin has a Github organization account.

Therefore, the endpoint you uses: https://docs.github.com/en/rest/reference/orgs#get-an-organization which only work for organizations, will return a not found http status for organization with user account (like eosforce).


The first step of your implementation should be to check whether the account you want to get repositories is an user or an organization account.

Then, to get user repositories, consume:

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

And to get organization repositories, consume:

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

See the Github documentation about Repositories for more details about how to consume those endpoints, if needed.

Upvotes: 2

Related Questions