Python PermissionError:[Errno 13]权限被拒绝:';C:/Users/PRATHAMESH/'。正在尝试通过google drive链接下载pdf
我正试图使用谷歌硬盘链接下载pdf文件,但当我试图存储它时,我的电脑拒绝我访问 我想让代码进入该url,打开文件并下载。如何授予存储数据的权限。我尝试了更改目录和文件夹的安全设置,但没有成功Python PermissionError:[Errno 13]权限被拒绝:';C:/Users/PRATHAMESH/'。正在尝试通过google drive链接下载pdf,python,python-3.x,google-chrome,selenium-webdriver,Python,Python 3.x,Google Chrome,Selenium Webdriver,我正试图使用谷歌硬盘链接下载pdf文件,但当我试图存储它时,我的电脑拒绝我访问 我想让代码进入该url,打开文件并下载。如何授予存储数据的权限。我尝试了更改目录和文件夹的安全设置,但没有成功 import requests def download_file_from_google_drive(id, destination): URL = "https://docs.google.com/uc?export=download" session = requests.Sess
import requests
def download_file_from_google_drive(id, destination):
URL = "https://docs.google.com/uc?export=download"
session = requests.Session()
response = session.get(URL, params = { 'id' : id }, stream = True)
token = get_confirm_token(response)
if token:
params = { 'id' : id, 'confirm' : token }
response = session.get(URL, params = params, stream = True)
save_response_content(response, destination)
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
def save_response_content(response, destination):
CHUNK_SIZE = 32768
with open(destination, "wb") as f:
for chunk in response.iter_content(CHUNK_SIZE):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
if __name__ == "__main__":
file_id = '1S6OuauRAYD6Ts7InfF8uEL4D6U_HeK1t'
destination = "C:/Users/PRATHAMESH/"
download_file_from_google_drive(file_id, destination)
但这是一个错误
PermissionError Traceback (most recent call last)
<ipython-input-9-c34c9d27dda6> in <module>
33 file_id = '1S6OuauRAYD6Ts7InfF8uEL4D6U_HeK1t'
34 destination = "C:/Users/PRATHAMESH/"
---> 35 download_file_from_google_drive(file_id, destination)
<ipython-input-9-c34c9d27dda6> in download_file_from_google_drive(id, destination)
13 response = session.get(URL, params = params, stream = True)
14
---> 15 save_response_content(response, destination)
16
17 def get_confirm_token(response):
<ipython-input-9-c34c9d27dda6> in save_response_content(response, destination)
25 CHUNK_SIZE = 32768
26
---> 27 with open(destination, "wb") as f:
28 for chunk in response.iter_content(CHUNK_SIZE):
29 if chunk: # filter out keep-alive new chunks
PermissionError: [Errno 13] Permission denied: 'C:/Users/PRATHAMESH/'
PermissionError回溯(最近一次调用)
在里面
33文件id='1s6ouaurayd6ts7inf8uel4d6u_HeK1t'
34 destination=“C:/Users/PRATHAMESH/”
--->35从谷歌硬盘下载文件(文件id,目的地)
从谷歌硬盘下载文件(id,目的地)
13 response=session.get(URL,params=params,stream=True)
14
--->15保存\u响应\u内容(响应、目标)
16
17 def获取确认令牌(响应):
在保存\响应\内容(响应、目标)中
25块大小=32768
26
--->27开放式(目的地,“wb”)作为f:
28用于响应的块。iter_内容(块大小):
29如果区块:#过滤掉保持活动的新区块
PermissionError:[Errno 13]权限被拒绝:“C:/Users/PRATHAMESH/”
如果您检查'C:/Users/PRATHAMESH/'
文件夹,您可能会在文件夹属性中看到:
这意味着该文件夹受到保护,不受任何试图写入该文件夹的“正常”应用程序的影响
避免这种情况的最简单方法是以管理员权限运行python应用程序(或终端应用程序)(右键单击->以管理员身份运行)
您还可以尝试从文件夹中删除写保护(我不完全确定windows是否会允许您对用户的配置文件执行写保护!),或者您可以,也可能应该,只需将目标目录更改为非系统目录,该目录将不具有严格的访问保护您可能需要一个文件名作为目标,不是目录名。