首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pyDrive给出FileNotDownloadableError错误

pyDrive给出FileNotDownloadableError错误
EN

Stack Overflow用户
提问于 2015-06-29 13:25:25
回答 3查看 1.7K关注 0票数 1

我正在尝试用PyDrive从google drive下载一个文件。我遵循了http://pythonhosted.org/PyDrive/filemanagement.html#download-file-content的指令。而且它在我自己的域中工作正常。

日志如下所示。

代码语言:javascript
复制
$ python driveDownload.py

Your browser has been opened to visit:
https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F2Fwww.googleapis.com%2Fauth%2Fdrive&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=837780293427-8m0mkibmrn8gg44i77pjg54ga70kpgae.apps.googleusercontent.com&access_type=offline 

Authentication successful.
title: a.xlsx, id: 0BzV-wECmF8MQTkdyQ0FHaVdwYlU
file Title identiefied :a.xlsx
aFromDrive.xlsx downloaded

我正尝试从客户的域中执行相同的操作,并给出以下错误

代码语言:javascript
复制
$ python driveDownload.py

    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=971731530622-7tdt9qhakv6q7i4edpfnqb5h7826eslv.apps.googleusercontent.com&access_type=offline                                                                                                                              

Authentication successful.
title: a.xlsx, id: 1l073W5s4dE0-dhFUXAMB-XROvOUC2z51NbfY69-bvIo
 file Title identiefied :a.xlsx                                
Traceback (most recent call last):                             
  File "driveDownload.py", line 29, in <module>                
    myFile.GetContentFile(myLocalPath)                         
  File "build/bdist.linux-x86_64/egg/pydrive/files.py", line 167, in GetContentFile
  File "build/bdist.linux-x86_64/egg/pydrive/files.py", line 36, in _decorated     
  File "build/bdist.linux-x86_64/egg/pydrive/files.py", line 210, in FetchContent  
pydrive.files.FileNotDownloadableError: No downloadLink/exportLinks for mimetype found in metadata

我的代码driveDownload.py如下

代码语言:javascript
复制
from pydrive.auth import GoogleAuth
import os
#authentication via the browser
#note... client_secrets.json is required for this that leads
#to the user authentication
gauth = GoogleAuth()
# gauth.LocalWebserverAuth()
from pydrive.drive import GoogleDrive

#accessing the drive
drive = GoogleDrive(gauth)


# Auto-iterate through all files that matches this query
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
fileName2Download= 'a.xlsx'
myLocalPath = 'aFromDrive.xlsx'
for file1 in file_list:
    print 'title: %s, id: %s' % (file1['title'], file1['id'])
    if file1['title'] == fileName2Download:
        print ' file Title identiefied :%s'% (file1['title']) 
        myFile = drive.CreateFile({'id': file1['id']})
        if os.path.exists(myLocalPath):
            os.remove(myLocalPath)

        myFile.GetContentFile(myLocalPath)
        print '%s downloaded ' %(myLocalPath)
        break
#         file1.download()

是否缺少某些设置?我能够列出我的客户的google驱动器中的所有文件。但是,当我尝试将文件下载到本地磁盘时出现错误

EN

回答 3

Stack Overflow用户

发布于 2016-10-30 07:43:24

我收到这个错误是因为我试图直接下载一个文件夹。仔细检查您的mimeType是否可以通过PyDrive下载。

票数 1
EN

Stack Overflow用户

发布于 2019-08-18 05:19:33

如果您正在创建文件夹,请确保复制文件ID(右键单击->获取可共享链接->复制链接的最后一部分),而不是文件夹ID。

票数 1
EN

Stack Overflow用户

发布于 2019-04-07 06:35:01

在我的例子中,id是错误的,我使用的是文件所在文件夹的id,所以请确保id只属于该文件,而不是文件夹。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31108339

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档