1

I am trying to download a file with PyDrive from google drive. I followed instruction http://pythonhosted.org/PyDrive/filemanagement.html#download-file-content. And it is working properly from my own domain.

Log is as below.

$ 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

I am trying the same thing from my client's domain and it is giving following error

$ 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

My code driveDownload.py is below

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()

Are there some settings that are missing ? I am able to list all the files in my client's google drive. However error appears when I am trying to download the file to my local disk

idom
  • 51
  • 6
  • 2
    I solved the problem. I had edited file with google sheet on my client domain and its mimeType had changed. Once I gave mimeType it started working myFile.GetContentFile(myLocalPath,mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') – idom Jun 29 '15 at 07:19

3 Answers3

1

I was getting this error because I was trying to download a folder directly. Double check that your mimeType is something which can be downloaded through PyDrive.

jplasmeier
  • 21
  • 4
0

in my case id was wrong, I used the id of the folder in which the file was situated, so be sure that the id is of that file only and not of the folder

0

If you're creating a folder, make sure you copy the file ID( right click->get shareable link->copy the last part of the link) not the folder ID.

Sakshi Gatyan
  • 1,903
  • 7
  • 13