0

I want to download a file from google drive using python and just the id of the file. I have the ids and the files are not sharable by the links. Thus the access is restricted just to me. What is the way to download such a file.

#downdrive.py
from pydrive.drive import GoogleDrive 
from pydrive.auth import GoogleAuth 

# For using listdir() 
import os 


# Below code does the authentication 
# part of the code 
gauth = GoogleAuth() 

# Creates local webserver and auto 
# handles authentication. 
gauth.LocalWebserverAuth()   
drive = GoogleDrive(gauth) 
fid_list=[]
# open file and read the content in a list
with open('gdrivefileid.txt', 'r') as filehandle:
    for line in filehandle:
        # remove linebreak which is the last character of the string
        currentPlace = line[:-1]
        # add item to the list
        fid_list.append(currentPlace)
        f = drive.CreateFile({'id': currentPlace})
        print('Downloading file %s from Google Drive' % f['title']) # 'hello.png'
        f.GetContentFile(f['title'])  # Save Drive file as a local file    

I got the following error when the authentication was successful the files are only accessible by me.

Downloading file client_secrets.json from Google Drive
Downloading file GEFHTBA.epub from Google Drive
Traceback (most recent call last):
  File "downdrive.py", line 27, in <module>
    f.GetContentFile(f['title'])  # Save Drive file as a local file
  File "C:\Users\prati\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydrive\files.py", line 211, in GetContentFile
    f = open(filename, 'wb')
PermissionError: [Errno 13] Permission denied: 'GEFHTBA.epub'
  • Is it poping up and requesting that you authorize your application? Looks like something is wrong with your authentication if it saying you dont have access. – Linda Lawton - DaImTo Jun 17 '20 at 20:47
  • @DaImTo I guess it was something with the .epub file but now I cannot find the files that are being downloaded – Pratik Patil Jun 17 '20 at 20:59

0 Answers0