pydrive错误:在元数据中找不到模仿类型的下载链接/导出链接 [英] Pydrive error: No downloadLink/exportLinks for mimetype found in metadata
问题描述
我正在尝试使用适用于python的pydrive模块自动从Google驱动器下载一个简单的文本文件.我不断收到以下错误:
I am trying to download a simple text file from google drive automatically with the pydrive module for python. I keep getting the following error:
回溯(最近通话最近): 文件"C:\ GIS \ AVGOPS \ Scripts \ GoogleDrive_Test.py",第20行,在 item.GetContentFile(r'C:\ Users \ pfilyer \ Desktop \ googedrive \'+ item ['title']) GetContentFile中的文件"C:\ Python27 \ ArcGIS10.4 \ lib \ site-packages \ pydrive \ files.py",第210行 self.FetchContent(mimetype,remove_bom) _decorated中的文件"C:\ Python27 \ ArcGIS10.4 \ lib \ site-packages \ pydrive \ files.py",第43行 返回decoratee(自己,* args,** kwargs) FetchContent中的文件"C:\ Python27 \ ArcGIS10.4 \ lib \ site-packages \ pydrive \ files.py",行265 在元数据中找不到模仿类型的downloadLink/exportLinks") FileNotDownloadableError:在元数据中找不到模仿类型的下载链接/导出链接
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文档,电子表格或其他非普通文件.
You are possibly trying to download a google document, spreadsheet or whatever else which is not a ordinary file.
不久前,当我尝试下载mimeType文件:application/vnd.google-apps.document时,出现了完全相同的错误.在下载之前,文档必须导出为其他格式. 检查以下内容:
I got exactly the same error a few moments ago, when I tried to download a file of mimeType: application/vnd.google-apps.document. The document has to be exported to other format before downloading. Check this:
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'])
这应该有效.
这篇关于pydrive错误:在元数据中找不到模仿类型的下载链接/导出链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!