上载大型fi时出现Google Drive API 400错误

2024-06-02 09:10:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一个上传脚本,使用可恢复上传将CSV文件上传到Google驱动器文件夹-我用这个作为参考

https://developers.google.com/api-client-library/python/guide/media_upload

请参阅下面的代码。在

对于大小为<;=20MB的文件,它似乎可以工作,但更大的文件会导致问题。在

我有一个43 MB的CSV文件,我试图使用5 MiB的块大小上载该文件,但在上一次块上载时出现400错误:

file_meta = {'title': 'test.csv', 'description': 'Test CSV', 'mimeType': 'text/csv', 'parents': [{'id': myfolder_key}]}
convert_to_Google_Sheets = True
chunk_size = 1024*1024*5
content = <MediaIoBaseUpload object, resumable, 5 MiB chunk size>
req = drive.files().insert(body=file_meta, media_body=content, convert=convert_to_Google_Sheets)
response is None
while not response:
  status, response = req.next_chunk()
  if status:
    print "Uploaded %d%%." % int(status.progress() * 100)

上传似乎进展顺利,直到我们到达最后一个块,当它以400错误终止时:

^{pr2}$

Tags: 文件csvtoconvertresponsestatus错误google
1条回答
网友
1楼 · 发布于 2024-06-02 09:10:12

我也遇到了同样的问题,一直以为是文件大小的问题,但结果发现文件大小只是这个问题的产物。在

问题是每个电子表格有200万个单元格的限制[1],当我(可能还有你的)CSV文件达到20MB左右时,列*行数突破了200万个单元格的限制。在

[1]https://support.google.com/drive/answer/37603?hl=en

相关问题 更多 >