在使用GitRelease
对象将资产上传到发布后,我看到了一些非常奇怪的行为。
案例:
import os
from github import Github
repo = Github(os.environ['GITHUB_ACCESS_TOKEN']).get_repo('<my-repo>')
release = repo.get_release(id='1.0.0')
repo.get_branch(branch='release') # works
release.upload_asset(path='/Users/elip/asset', content_type='application/octet-stream')
repo.get_branch(branch='release') # throws the exception
例外:
Traceback (most recent call last):
File "pygithub_bug.py", line 16, in <module>
repo.get_branch(branch='release')
File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Repository.py", line 1191, in get_branch
self.url + "/branches/" + branch
File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 185, in requestJsonAndCheck
return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 198, in __check
raise self.__createException(status, responseHeaders, output)
File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 210, in __createException
elif status == 404 and output.get("message") == "Not Found":
AttributeError: 'NoneType' object has no attribute 'get'
值得一提的是,不仅仅是get_branch
崩溃了,每个需要从 Github 获取某些内容的方法都因此错误而失败。
另外值得一提的是,有时,例外是不同的:
Traceback (most recent call last):
File "pygithub_bug.py", line 19, in <module>
repo.get_commit(sha='release')
File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Repository.py", line 1267, in get_commit
self.url + "/commits/" + sha
File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 185, in requestJsonAndCheck
return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 231, in requestJson
return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 275, in __requestEncode
url = self.__makeAbsoluteUrl(url)
File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 343, in __makeAbsoluteUrl
assert o.hostname in [self.__hostname, "uploads.github.com"], o.hostname
AssertionError: api.github.com
当我在上传之前添加repo.default_branch
(或者我假设任何需要 REST 调用的属性调用)时,就会发生这种异常。
有人可以透露一些信息吗? 我在这里错过了什么吗?
谢谢
忘了提及我的环境:
蟒蛇 2.7.14
MacOS 高山脉
PyGithub 1.38
这是一个已知问题,请参阅我的 PR #771 将解决此错误,开发人员将合并下一个版本
惊人的
谢谢👍
是的,将尽快合并#771。
很想看到这个合并。 遇到同样的问题。
我为此使用的解决方法非常简单。 基本上每次文件上传后,我都会重新创建 github、repo 和 release 实例。 这是伪代码(完整代码在Satsuki 中):
try:
release_asset = release.upload_asset (
path,
**args
)
except Exception as e:
error = e
finally:
gh = github.Github(...)
repo = gh.get_repo(...)
release = repo.get_release(...)
# see if e is an actual error, usually it's not
是的
来自:nurupo通知@github.com
发送时间:2018 年 6 月 25 日星期一下午 2:32:26
至:PyGithub/PyGithub
抄送:万留洋; 评论
主题:回复:[PyGithub/PyGithub] 将资产上传到发布会破坏存储库对象 (#779)
应该通过合并 #771 https://github.com/PyGithub/PyGithub/pull/771来解决?
—
您收到此消息是因为您发表了评论。
直接回复本邮件,在 GitHub 上查看https://github.com/PyGithub/PyGithub/issues/779#issuecomment-399846062 ,或者将线程静音https://github.com/notifications/unsubscribe-auth/AA- CRnGC3DneR2a5__s9jFIwPiPraMrFks5uAIP6gaJpZM4Tt_wu 。
它应该由 #771 修复。 你们可以试试大师吗? 我可能很快就会发布一个版本。
@sfdye就可以了
@sfdye看起来不错👍,谢谢!
顺便说一句,我不确定你是如何减少发布的,但是你可以看看我专门编写的一个工具,用于管理托管在 GIthub 上的 Python 项目的发布。 它被称为pyci ,也许你可以从中受益......(对不起无耻的插件,但它似乎合适:))
@iliapolo酷,会看看。