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

标签 python python-2.7 pydrive

我正在尝试使用 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/

相关文章:

python - 在 Dash Python 中下载具有列格式的 Excel 文件

python - 根据第三个变量改变散点图中的标记样式

python - 如何使用 Python 将 URL 查询字符串转换为元组列表?

python - 你能澄清一下Python中的这个引用问题吗?

python - 无法使用 PyDrive 在谷歌驱动器中的文件夹之间移动文件

python - 生成缓冲区半径多边形 - 可能的投影问题

python - 编码西格玛公式?

python - 提取两个句子之间不同的词

python - 使用 PyDrive 管理来自公共(public) Google 云端硬盘 URL 的文件