Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用python在github上推送压缩文件_Python 3.x_Github_Github Api_Gitpython - Fatal编程技术网

Python 3.x 使用python在github上推送压缩文件

Python 3.x 使用python在github上推送压缩文件,python-3.x,github,github-api,gitpython,Python 3.x,Github,Github Api,Gitpython,我想使用python代码或API在github上推送一个.zip文件,但在使用stackoverflow上找到的一些资源进行推送时,该文件正在被推送,但推送的数据已损坏,无法检索回来 试过这个,, 尝试使用git hub API v3在github上上载zip文件尝试使用git hub API v3在github上上载zip文件在的帮助下,您可以使用以下代码段: import base64 now = datetime.datetime.now() # read binary file and

我想使用python代码或API在github上推送一个.zip文件,但在使用stackoverflow上找到的一些资源进行推送时,该文件正在被推送,但推送的数据已损坏,无法检索回来

试过这个,,

尝试使用git hub API v3在github上上载zip文件

尝试使用git hub API v3在github上上载zip文件

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

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
在的帮助下,您可以使用以下代码段:

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

欢迎使用StackOverflow,回答问题时请更具体,可以添加op解决问题的步骤说明。欢迎使用StackOverflow,回答问题时请更具体,可以添加op解决问题的步骤说明。欢迎使用StackOverflow!分享你的研究成果对每个人都有帮助。告诉我们您尝试了什么,以及为什么它不能满足您的需求。这表明你花了时间来帮助自己,它使我们避免重复显而易见的答案,最重要的是,它帮助你得到一个更具体和相关的答案!另请参见:欢迎来到StackOverflow!分享你的研究成果对每个人都有帮助。告诉我们您尝试了什么,以及为什么它不能满足您的需求。这表明你花了时间来帮助自己,它使我们避免重复显而易见的答案,最重要的是,它帮助你得到一个更具体和相关的答案!另见: