pythonpython-3.xgithubgithub-api

Why I got Exception "403 Repository access blocked'' using pygithub?


I'm trying to scrapy github users' favorite programming language through pygithub,but so strange,every time I want to scrapy user--ELLIOTTCABLE' reposity i got following Exception:

Traceback (most recent call last):
File "/home/gf/KuaiPan/code/Python/Data Mining/test.py", line 14, in <module>
repo = user.get_repo(j)
File "/usr/lib/python3.4/site-packages/github/NamedUser.py", line 449, in get_repo
"/repos/" + self.login + "/" + name
File "/usr/lib/python3.4/site-packages/github/Requester.py", line 169, in requestJsonAndCheck
return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
File "/usr/lib/python3.4/site-packages/github/Requester.py", line 177, in __check
raise self.__createException(status, responseHeaders, output)
github.GithubException.GithubException: 403 {'message': 'Repository access blocked', 'block': {'reason': 'unavailable', 'created_at': '2014-01-31T14:32:14-08:00'}}

My python code is below:

#!/usr/bin/env python3
from github import Github


ACCESS_TOKEN = 'my credential'
client = Github(ACCESS_TOKEN, per_page=100)
user = client.get_user('ELLIOTTCABLE')
repo_list = [repo.name for repo in user.get_repos() if not repo.fork]
print(repo_list)

for j in repo_list:
    repo = user.get_repo(j)
    lang = repo.language
    print(j,':',lang)

Solution

  • The 403 HTTP Status denotes a forbidden request, thus you have provided credentials that can't let you access some endpoints.

    So you may need to provide a valid credentials (username / password) when creating the Github object:

    #!/usr/bin/env python3
    from github import Github
    
    ACCESS_USERNAME = 'username'
    ACCESS_PWD = "password"
    client = Github(ACCESS_USERNAME, ACCESS_PWD, per_page=100)
    user = client.get_user('ELLIOTTCABLE')
    repo_list = [repo.name for repo in user.get_repos() if not repo.fork]
    print(repo_list)
    
    for j in repo_list:
        repo = user.get_repo(j)
        lang = repo.language
        print(j,':',lang)
    

    This should work just fine.