你好,
PyGithub是https://github.com/Borkason/google-code-issues-migrator的一部分,它本身是一个废弃项目的分支,最近我在该脚本中收到了随机的401 Bad Credentials异常。 过去没有出现这种异常,这就是为什么我认为它可能与PyGithub处理凭据的方式有关。 也许Github在过去1或2个月内发生了变化?
我在异常的外观上找不到任何模式。 我认为这是随机的。
这就是我所做的
我在__main__
一次身份验证: https :
然后,我开始迁移所有问题。 该脚本会提取所有问题,并使用google code api做一些事情,然后在github中创建新问题,包括注释。 通常,在问题创建过程中,我会收到例外情况。 始终处于随机点(有时添加2期后,有时添加100期后...
_我希望您能提供任何帮助。_
这是例外
Traceback (most recent call last):
File "migrateissues.py", line 529, in <module>
process_gcode_issues(existing_issues)
File "migrateissues.py", line 332, in process_gcode_issues
add_comments_to_issue(github_issue, gid)
File "migrateissues.py", line 236, in add_comments_to_issue
existing_comments = [ comment.body for comment in github_issue.get_comments() ]
File "/usr/local/lib/python2.7/dist-packages/PyGithub-1.12.2-py2.7.egg/github/PaginatedList.py", line 35, in __iter__
newElements = self.__grow()
File "/usr/local/lib/python2.7/dist-packages/PyGithub-1.12.2-py2.7.egg/github/PaginatedList.py", line 47, in __grow
newElements = self._fetchNextPage()
File "/usr/local/lib/python2.7/dist-packages/PyGithub-1.12.2-py2.7.egg/github/PaginatedList.py", line 104, in _fetchNextPage
headers, data = self.__requester.requestJsonAndCheck("GET", self.__nextUrl, self.__nextParams, None)
File "/usr/local/lib/python2.7/dist-packages/PyGithub-1.12.2-py2.7.egg/github/Requester.py", line 84, in requestJsonAndCheck
return self.__check(*self.requestJson(verb, url, parameters, input))
File "/usr/local/lib/python2.7/dist-packages/PyGithub-1.12.2-py2.7.egg/github/Requester.py", line 92, in __check
raise GithubException.GithubException(status, output)
github.GithubException.GithubException: 401 {u'message': u'Bad credentials'}
你好!
在过去的几天中,我也遇到了这个问题。 它一定是GIthub上的bug,与PyGithub无关。 可以使用以下shell脚本来复制它(以您的登录名和密码作为参数来调用它):
#!/bin/sh
USER=$1
PASSWORD=$2
CONTINUE=1
while [ $CONTINUE == "1" ]
do
OUTPUT=$(curl --include https://$USER:[email protected]/user 2>&1)
if echo "$OUTPUT" | grep "200 OK" >/dev/null
then
echo OK
else
date
echo "$OUTPUT"
CONTINUE=0
fi
done
它输出一定数量的“ OK”,并以错误消息结尾,导致PyGithub抛出异常:
[...]
OK
OK
OK
OK
Thu Mar 21 20:35:50 RST 2013
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 35 100 35 0 0 57 0 --:--:-- --:--:-- --:--:-- 70HTTP/1.1 401 Unauthorized
Server: GitHub.com
Date: Thu, 21 Mar 2013 19:35:53 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Status: 401 Unauthorized
X-GitHub-Media-Type: github.beta
Content-Length: 35
{
"message": "Bad credentials"
}
您可能需要直接向Github提交错误。
昨天我没问题,今天又完全被窃听了。
我做了一个快速而肮脏的黑客来解决PaginatedList.py中的Github问题
def _fetchNextPage(self):
myWorkaround = True
while myWorkaround:
try:
headers, data = self.__requester.requestJsonAndCheck("GET", self.__nextUrl, self.__nextParams, None)
myWorkaround = False
except:
pass
[…]
今天,我还在一个简单的脚本上遇到了这个问题,该脚本仅对API进行了一些(非分页)请求。 对我而言,这绝对不重要,因此我不会花时间自己联系GitHub。
这个问题比分页更为笼统,因此,如果您确实需要解决方法,则可以选择在Requester.py中进行:
替换第143行
status, responseHeaders, output = self.__requestRaw(verb, url, requestHeaders, encoded_input)
通过类似的东西
status = 401
retries = 5
while retries > 0 and status == 401:
status, responseHeaders, output = self.__requestRaw(verb, url, requestHeaders, encoded_input)
retries -= 1
(我根本没有测试过)
感谢您提供该代码段:+1:
我联系了Github,但他们似乎无法复制该问题。 但是由于有了解决方法,所以我也不会再花时间了:)
干杯。