【问题标题】:Not able to instantiate pyGithub module's Github() object无法实例化 pyGithub 模块的 Github() 对象
【发布时间】:2017-01-17 11:42:43
【问题描述】:

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

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 对象创建实例)我被卡住了。休息一下,我知道,可能很容易。

当我将 URL 从“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

【问题讨论】:

    标签: pygithub


    【解决方案1】:

    应该是这样的:

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

    【讨论】:

      猜你喜欢
      • 2021-10-02
      • 2014-05-30
      • 2014-06-04
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多