gpt4 book ai didi

python - 驱动器错误 : No downloadLink/exportLinks for mimetype found in metadata

转载 作者:行者123 更新时间:2023-11-28 20:35:52 37 4
gpt4 key购买 nike

我正在尝试使用 python 的 pydrive 模块自动从谷歌驱动器下载一个简单的文本文件。我不断收到以下错误:

Traceback (most recent call last): File "C:\GIS\AVGOPS\Scripts\GoogleDrive_Test.py", line 20, in item.GetContentFile(r'C:\Users\pfilyer\Desktop\googedrive\' + item['title']) File "C:\Python27\ArcGIS10.4\lib\site-packages\pydrive\files.py", line 210, in GetContentFile self.FetchContent(mimetype, remove_bom) File "C:\Python27\ArcGIS10.4\lib\site-packages\pydrive\files.py", line 43, in _decorated return decoratee(self, *args, **kwargs) File "C:\Python27\ArcGIS10.4\lib\site-packages\pydrive\files.py", line 265, in FetchContent 'No downloadLink/exportLinks for mimetype found in metadata') FileNotDownloadableError: No downloadLink/exportLinks for mimetype found in metadata

有什么建议吗?

import pydrive
from pydrive.drive import GoogleDrive

from pydrive.auth import GoogleAuth

gauth = GoogleAuth()
gauth.LoadCredentialsFile(r"C:\Users\XXXXX\.credentials\drive-python-quickstart.json")
drive = GoogleDrive(gauth)

print "Auth Success"

folder_id = '0BxbuUXtrs7adSFFYMG0zS3VZNFE'
lister = drive.ListFile({'q': "'%s' in parents" % folder_id}).GetList()
for item in lister:
print item['title']
item.GetContentFile(r'C:\Users\XXXXX\Desktop\googedrive\\' + item['title'])

最佳答案

您可能正在尝试下载 google 文档、电子表格或任何其他非普通文件的文件。

我刚才遇到了完全相同的错误,当时我尝试下载 mimeType 文件:application/vnd.google-apps.document。下载前必须将文档导出为其他格式。检查这个:

import pydrive
from pydrive.drive import GoogleDrive

from pydrive.auth import GoogleAuth

gauth = GoogleAuth()
gauth.LoadCredentialsFile(r"C:\Users\XXXXX\.credentials\drive-python- quickstart.json")
drive = GoogleDrive(gauth)

print "Auth Success"

folder_id = '0BxbuUXtrs7adSFFYMG0zS3VZNFE'
lister = drive.ListFile({'q': "'%s' in parents" % folder_id}).GetList()
for item in lister:
print(item['title'])
# this should tell you which mimetype the file you're trying to download
# has.
print('title: %s, mimeType: %s' % (item['title'], item['mimeType']))
mimetypes = {
# Drive Document files as PDF
'application/vnd.google-apps.document': 'application/pdf',

# Drive Sheets files as MS Excel files.
'application/vnd.google-apps.spreadsheet': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'

# see https://developers.google.com/drive/v3/web/mime-types
}
download_mimetype = None
if file['mimeType'] in mimetypes:
download_mimetype = mimetypes[file['mimeType']]
file.GetContentFile(file['title'], mimetype=download_mimetype)

item.GetContentFile(r'C:\Users\XXXXX\Desktop\googedrive\\' + item['title'], mimetype=download_mimetype)
else:
item.GetContentFile(r'C:\Users\XXXXX\Desktop\googedrive\\' + item['title'])

这应该有效。

关于python - 驱动器错误 : No downloadLink/exportLinks for mimetype found in metadata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46155300/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com