无法实例化pyGithub模块的Github()对象

时间:2017-01-17 11:42:44

标签: pygithub

任何人对使用PyGithub模块有任何想法。在实例化git对象时遇到问题。对于我尝试过的任何网址,问题都是一样的。

from github import Github
g= Github("None", "None", "https://github.com/OpenSCAP")
#g = Github()
g.get_user().name       #getting exception right here.
print( g.get_user().name)
for repo in g.get_user().get_repos():
    print (repo.name)

以下是追溯。

    pydev debugger
Traceback (most recent call last):
  File "C:\EasyEclipse-for-Python-1.3.1\plugins\org.python.pydev.debug_1.3.13\pysrc\pydevd.py", line 803, in <module>
    debugger.run(setup['file'], None, None)
  File "C:\EasyEclipse-for-Python-1.3.1\plugins\org.python.pydev.debug_1.3.13\pysrc\pydevd.py", line 655, in run
    execfile(file, globals, locals) #execute the script
  File "C:\MyDrive\SecureShield\GitHub\src\mygit.py", line 5, in <module>
    g.get_user().name
  File "C:\Python27\Lib\site-packages\github\AuthenticatedUser.py", line 221, in name
    self._completeIfNotSet(self._name)
  File "C:\Python27\Lib\site-packages\github\GithubObject.py", line 248, in _completeIfNotSet
    self._completeIfNeeded()
  File "C:\Python27\Lib\site-packages\github\GithubObject.py", line 252, in _completeIfNeeded
    self.__complete()
  File "C:\Python27\Lib\site-packages\github\GithubObject.py", line 257, in __complete
    self._url.value
  File "C:\Python27\Lib\site-packages\github\Requester.py", line 172, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
  File "C:\Python27\Lib\site-packages\github\Requester.py", line 180, in __check
    raise self.__createException(status, responseHeaders, output)
github.GithubException.GithubException

苦苦挣扎了这么多天。只有第一次调用自己(为Github对象创建实例)我被卡住了。休息我知道,可能很容易。

当我将网址从“https://github.com/OpenSCAP”更改为“http://github.com/OpenSCAP”时,获取以下回溯。完全不了解这个问题。

    pydev debugger
None
Repository(full_name=None)
Traceback (most recent call last):
  File "C:\EasyEclipse-for-Python-1.3.1\plugins\org.python.pydev.debug_1.3.13\pysrc\pydevd.py", line 803, in <module>
    debugger.run(setup['file'], None, None)
  File "C:\EasyEclipse-for-Python-1.3.1\plugins\org.python.pydev.debug_1.3.13\pysrc\pydevd.py", line 655, in run
    execfile(file, globals, locals) #execute the script
  File "C:\MyDrive\SecureShield\GitHub\src\mygit.py", line 9, in <module>
    print (repo.name)
  File "C:\Python27\Lib\site-packages\github\Repository.py", line 435, in name
    self._completeIfNotSet(self._name)
  File "C:\Python27\Lib\site-packages\github\GithubObject.py", line 248, in _completeIfNotSet
    self._completeIfNeeded()
  File "C:\Python27\Lib\site-packages\github\GithubObject.py", line 252, in _completeIfNeeded
    self.__complete()
  File "C:\Python27\Lib\site-packages\github\GithubObject.py", line 257, in __complete
    self._url.value
  File "C:\Python27\Lib\site-packages\github\Requester.py", line 172, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
  File "C:\Python27\Lib\site-packages\github\Requester.py", line 213, in requestJson
    return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
  File "C:\Python27\Lib\site-packages\github\Requester.py", line 243, in __requestEncode
    url = self.__makeAbsoluteUrl(url)
  File "C:\Python27\Lib\site-packages\github\Requester.py", line 304, in __makeAbsoluteUrl
    if url.startswith("/"):
AttributeError: 'NoneType' object has no attribute 'startswith'
Exception AttributeError: "'NoneType' object has no attribute 'print_exc'" in <function _remove at 0x022C64B0> ignored

1 个答案:

答案 0 :(得分:0)

应该是这样的:

from github import Github
g = Github("ClaudiuCreanga", "private_token")
repo = g.get_repo("ClaudiuCreanga/magento2-store-locator-stockists-extension")