我试图下载一个googledrive电子表格作为Excel文件。据我所知,googledriveapi只需为export_media请求指定一个不同的mime类型,就可以使这个过程变得非常简单。在
基于教程脚本,我可以成功地将电子表格下载为CVS并打开Office工作表。太好了!在
但是,当mime类型设置为application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
-时,下载程序将继续从流中读取,而不会停止,也不会增加状态进度。在
完整的脚本是here。要运行,请按照说明在googledriveapi文档中创建应用程序here
违规代码如下:
file_id = 'my spreadsheet id'
request = service.files().export_media(fileId=file_id, mimeType='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
fh = FileIO('data.xls', 'wb')
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print("Download %d%%." % int(status.progress() * 100))
它继续打印Download 0%
,并且从不停止。在
结果是
MediaBaseIODownload
依赖于“content rangeor
content length”的存在来知道何时停止。在但是,在调试器中,我可以看到它们不在响应中。因此,它不知道什么时候完成。在
^{pr2}$解决方案是不运行部分下载,而是全部下载:
相关问题 更多 >
编程相关推荐