使用 python 在 github 上推送压缩文件

pushing zipped files on github using python

我想使用 python 代码或 API 在 github 上推送一个 .zip 文件,但是在使用我在 Whosebug 上找到的一些资源时,文件正在被已推送,但推送的数据已损坏,无法取回。

试过了,

尝试使用 git hub API v3 将 zip 文件上传到 github

PyGithub 的帮助下,您可以使用此代码段:

import base64
now = datetime.datetime.now()
# read binary file and convert it to ascii code using base64 library
data = base64.b64encode(open(file_name, "rb").read())
path = "{}/{}/{}".format(now.year, now.month, "tweets.zip")
# pygithub needs string for creating blob so we decode binary data to utf-8 to be parsed correctly
blob = repo.create_git_blob(data.decode("utf-8"), "base64")
element = InputGitTreeElement(path=path, mode='100644', type='blob', sha=blob.sha)
element_list.append(element)
tree = repo.create_git_tree(element_list, base_tree)
parent = repo.get_git_commit(master_sha)
commit = repo.create_git_commit("commit_message", tree, [parent])
master_ref.edit(commit.sha)```


  [1]: https://github.com/PyGithub/PyGithub