微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 Python3.x 将 60 或更多 Mbs 的数据库文件提交并推送到 GitHub API?

如何解决如何使用 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,token)

这段代码给了我以下错误

KeyError: 'sha'

但它在小文件上运行良好。

当我尝试在代码中运行 data 变量时,我收到以下消息,这让我认为我需要一种不同的方式来接受 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'}

有人知道如何处理吗?我很难点击建议的链接

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?