1

i want to push a .zip file on github using python code or API, but in doing so with some resources which i found on stackoverflow, the file is being pushed but the data pushed is corrupted and cannot be retrieved back.

Tried this, How do I push new files to GitHub?

User6670
  • 160
  • 5
  • Welcome to StackOverflow! Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [ask] – Hille May 06 '19 at 08:00

2 Answers2

1

with the help of PyGithub , You Can Use this Snippet:

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
smbanaei
  • 1,123
  • 8
  • 14
0

Try using git hub API v3 to upload the zip file on github

  • Welcome to StackOverflow, please be more specific when answering questions, may add a step to step description of what the op should do to solve the problem. – Hille May 06 '19 at 07:59