簡體   English   中英

使用 Python 驅動器 API 無法上傳 > 200 MB csv 文件

[英]Unable to upload > 200 MB csv file using Python Drive API

我正在嘗試使用驅動器 API 自動化我的日常任務,當我嘗試上傳較大的文件(> 300 MB CSV)時遇到錯誤,而以下代碼適用於上傳較小的文件(<100 MB)。 補充說我正在我的 Debian Linux VM 中運行該片段,並且我的 VM 端沒有問題。

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.```

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

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

通過將我的 httplib2 package 降級到 0.13.1 來解決

此處使用的參考

謝謝 ! @balderman

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM