【发布时间】:2017-03-18 02:36:09
【问题描述】:
我正在使用 Google Driver API python 库将文件下载为 CSV 格式。
google_drive_service = get_service()
mimeType = 'text/csv'
request = google_drive_service.files().export_media(fileId='abc', mimeType=mimeType)
fh = io.BytesIO()
downloader = MediaIoBaseDownload(fh, request)
done = False
while not done:
status, done = downloader.next_chunk()
print "Download %d%%." % int(status.progress() * 100)
fh.seek(0)
content = fh.getvalue()
由于它是一个大标签,因此下载过程会按块进行分解。它不断打印出“Downloading 0%”。当代码检查下载过程时,我循环浏览了库代码。一直显示“Downloading 0%”的原因是http响应没有“content-range”和“content-length”头,导致进程检查问题。
如果您有兴趣复制此过程。创建一个电子表格并填写“A:E”列和“1:10000”行的单元格值。让我知道是否有人遇到同样的问题或知道为什么会发生这种情况。这是 Gdrive 代码:https://github.com/google/google-api-python-client/blob/master/googleapiclient/http.py#L664-L691
【问题讨论】: