python-3.x - 如何使用 Python3.x 提交和推送 60 或更多 Mbs 的数据库文件到 GitHub API?
问题描述
我一直在寻找一种更好的方法来自动将新文件或现有文件上传到我的存储库。以下代码只能更新现有文件(现在对我来说没什么大不了的)并且不适用于大文件。
def push_to_github(filename, repo, branch, token):
url="https://api.github.com/repos/"+repo+"/contents/"+filename
base64content=base64.b64encode(open(filename,"rb").read())
data = requests.get(url+'?ref='+branch, headers = {"Authorization": "token "+token}).json()
sha = data['sha']
if base64content.decode('utf-8')+"\n" != data['content']:
message = json.dumps({"message":"update",
"branch": branch,
"content": base64content.decode("utf-8") ,
"sha": sha
})
resp=requests.put(url, data = message, headers = {"Content-Type": "application/json", "Authorization": "token "+token})
print(resp)
else:
print("nothing to update")
token = "lskdlfszezeirzoherkzjehrkzjrzerzer"
filename="foo.txt"
repo = "you/test"
branch="master"
push_to_github(filename, repo, branch, token)
这段代码给了我以下错误:
KeyError: 'sha'
但它适用于一个小文件。
当我尝试在代码中运行数据变量时,我收到以下消息,这让我认为我需要一种不同的方式来接受更大的 60 Mbs 文件。
{'message': 'This API returns blobs up to 1 MB in size. The requested blob is too large to fetch via the API, but you can use the Git Data API to request blobs up to 100 MB in size.', 'errors': [{'resource': 'Blob', 'field': 'data', 'code': 'too_large'}],
'documentation_url': 'https://docs.github.com/rest/reference/repos#get-repository-content'}
有谁知道如何处理这个?我很难遵循建议的链接。
解决方案
推荐阅读
- fonts - 如何使用所有连字复制参考
- django - Gain time intervals in Django
- python - ['kenlm/build/bin/build_binary','-a','255','-q','8','-v','trie','lm_filtered.arpa','/content/lm. binary']' 返回非零退出状态 1
- linux - AWS CLI version 2 path not found
- altair - Altair Changing legend color
- c - Linux中gcc链接期间的多个定义错误
- webview - Webview PageFinish URL 错误
- javascript - 在 React 组件中使用 Map 函数
- controls - 具有 2 个协变量的 R Lavaan 中介分析
- python - 我正在做 Web Scraping,使用 dryscrape 和美丽的汤。但是 Colab 没有找到 xvfb,尽管它已安装。为什么?