【问题标题】:Unable to upload > 200 MB csv file using Python Drive API无法使用 Python Drive API 上传 > 200 MB 的 csv 文件
【发布时间】:2020-12-06 13:31:35
【问题描述】:

我正在尝试使用驱动器 API 自动化我的日常任务,当我尝试上传较大的文件 (> 300 MB CSV) 时遇到错误,而以下代码适用于上传较小的文件 (

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import os



gauth = GoogleAuth()
# Try to load saved client credentials if already done
gauth.LoadCredentialsFile("mycreds.txt")


drive_path = '<drive_id>'

data_to_be_uploaded = "my_big_file.csv"
    
# Declared the variable so that it will be uploaded as per the last date
file1 = drive.CreateFile({'title': my_big_csv_data+'.csv',
                          'parents': [{'id': drive_path}]
                          })
file1.SetContentFile(data_to_be_uploaded)
file1.Upload()

错误如下

  File "test_code.py", line 72, in <module>
    file1.Upload()
  File "/usr/share/hunch/lib/python3.6/site-packages/pydrive/files.py", line 285, in Upload
    self._FilesInsert(param=param)
  File "/usr/share/hunch/lib/python3.6/site-packages/pydrive/auth.py", line 75, in _decorated
    return decoratee(self, *args, **kwargs)
  File "/usr/share/hunch/lib/python3.6/site-packages/pydrive/files.py", line 369, in _FilesInsert
    http=self.http)
  File "/usr/share/hunch/lib/python3.6/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/share/hunch/lib/python3.6/site-packages/googleapiclient/http.py", line 810, in execute
    _, body = self.next_chunk(http=http, num_retries=num_retries)
  File "/usr/share/hunch/lib/python3.6/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/share/hunch/lib/python3.6/site-packages/googleapiclient/http.py", line 970, in next_chunk
    headers=headers)
  File "/usr/share/hunch/lib/python3.6/site-packages/oauth2client/transport.py", line 175, in new_request
    redirections, connection_type)
  File "/usr/share/hunch/lib/python3.6/site-packages/oauth2client/transport.py", line 282, in request
    connection_type=connection_type)
  File "/usr/share/hunch/lib/python3.6/site-packages/httplib2/__init__.py", line 1994, in request
    cachekey,
  File "/usr/share/hunch/lib/python3.6/site-packages/httplib2/__init__.py", line 1690, in _request
    content,
httplib2.RedirectMissingLocation: Redirected but the response is missing a Location: header.```

【问题讨论】:

  • 如果文件大小有问题 - 为什么不尝试压缩文件?
  • @balderman:试过了,但同样的错误。
  • 压缩后的文件大小是多少?
  • @balderman:大约 50 MB。但仍然收到错误 httplib2.RedirectMissingLocation: Redirected but response is missing a Location: header.

标签: python google-drive-api pydrive


【解决方案1】:

某些类型的文件有 100MB 的限制

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

【讨论】:

    【解决方案2】:

    通过将我的 httplib2 包降级到 0.13.1 解决

    引用使用here

    谢谢! @balderman

    【讨论】:

      猜你喜欢
      • 2020-12-05
      • 2022-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-06
      • 2017-07-31
      相关资源
      最近更新 更多