编程语言
首页 > 编程语言> > python – Pydrive错误:没有在元数据中找到的mimetype的downloadLink / exportLinks

python – Pydrive错误:没有在元数据中找到的mimetype的downloadLink / exportLinks

作者:互联网

我试图使用pydrive模块为python自动从谷歌驱动器下载一个简单的文本文件.我一直收到以下错误:

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,python-2-7,pydrive
来源: https://codeday.me/bug/20191008/1872899.html