Python:只有您可以访问时,才从Google驱动器下载文件

问题描述 投票:0回答:1

我想使用python和文件ID从Google驱动器下载文件。我有ID,并且文件不可通过链接共享。因此,访问仅限于我。用什么方法下载这样的文件。

#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'
python google-api google-drive-api permission-denied pydrive
1个回答
0
投票

我意识到这是导致.enub的问题

© www.soinside.com 2019 - 2024. All rights reserved.