如何解决pygithub get_contents thorws 错误 UnknownObjectException
我正在 Windows 上编写一个 python 脚本,它将以用户名作为输入,并下载他的存储库的主分支代码。我正在使用 pygithub 模块。我正在使用 github 模块的 get_contents
方法下载代码。
在下面的 code_snippet 中,python 执行 get_content
方法时会抛出 UnknownObjectException
。
我传递的 Server_path 是 "./Gitrepo"
。
下面是代码片段:
Server_path='Path where I want to save the code'
sha=branch
repository is git repo
def download_directory(repository,sha,server_path):
"""
Download all contents at server_path with commit tag sha in
the repository.
"""
if os.path.exists(server_path):
shutil.rmtree(server_path)
os.makedirs(server_path)
contents = repository.get_contents(path=server_path,ref=sha)
for content in contents:
#print("content.path %s" % content.path)
if content.type == 'dir':
print("content.path %s" % content.path)
download_directory(repository,content.path)
else:
try:
path = content.path
file_content = repository.get_contents(path,ref=sha)
file_data = base64.b64decode(file_content.content)
file_out = open(content.name,"wb+")
file_out.write(file_data)
file_out.close()
except (GithubException,IOError) as exc:
logging.error('Error processing %s: %s',content.path,exc)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。