Python: загрузить файл с Google Диска, когда только вы можете получить к нему доступ - PullRequest
0 голосов
/ 17 июня 2020

Я хочу загрузить файл с диска Google, используя python и просто идентификатор файла. У меня есть идентификаторы, и файлы не доступны по ссылкам. Таким образом, доступ ограничен только мной. Как можно загрузить такой файл.

#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    

Я получил следующую ошибку, когда аутентификация прошла успешно: файлы доступны только мне.

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'
...