python - Python:只有您可以访问时从谷歌驱动器下载文件
问题描述
我想使用 python 从谷歌驱动器下载一个文件,只是文件的 id。我有 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'
解决方案
推荐阅读
- javascript - 未捕获的类型错误:无法读取未定义的属性“查询”
- sqlite - SQLIte 和 EF 中的 NOT NULL 约束失败
- python-3.x - 无法在 selenium 和 python 中同时设置多个 chrome 选项(阻止通知和 cookie)
- python - 用beautifulsoup python在html中查找特定的子元素
- methods - 求任意两个给定整数的和
- powershell - 从多个目录中删除多个文件
- c - 如何为带有数组的结构分配内存?
- git - 查找源代码控制下包含在 .gitignore 中的所有文件
- python - 在本地化页面中删除缓存的问题
- android - android.widget.SelectionActionModeHelper$TextClassificationHelper.init (SelectionActionModeHelper.java:974)