简体   繁体   English

Errno 13 下载文件的权限被拒绝

[英]Errno 13 Permission denied for downloading files

I'm trying to download zip files from a url, and place them in a directory我正在尝试从 url 下载 zip 文件,并将它们放在一个目录中

import requests 

def download_url(url, save_path, chunk_size=128):
    r = requests.get(url, stream=True)
    with open(save_path, 'wb') as fd:
        for chunk in r.iter_content(chunk_size=chunk_size):
            fd.write(chunk)

url = 'https://www1.nseindia.com/content/historical/EQUITIES/1994/NOV/cm23NOV1994bhav.csv.zip'
save_path = 'D:/folder/Programming/Python/trading/Bhavcopy/'

download_url(url,save_path)

I get the following output我得到以下输出

Traceback (most recent call last): File "d:\\folder\\Programming\\Python\\trading\\bhavcopy.py", line 12, in module download_url(url,save_path) File "d:\\folder\\Programming\\Python\\trading\\bhavcopy.py", line 5, in download_url with open(save_path, 'wb') as fd: PermissionError: [Errno 13] Permission denied: 'D:/folder/Programming/Python/trading/Bhavcopy/'回溯(最近一次调用):文件“d:\\folder\\Programming\\Python\\trading\\bhavcopy.py”,第 12 行,在模块 download_url(url,save_path) 文件“d:\\folder\\Programming\\Python\\trading\\ bhavcopy.py”,第 5 行,在 download_url 中使用 open(save_path, 'wb') 作为 fd: PermissionError: [Errno 13] Permission denied: 'D:/folder/Programming/Python/trading/Bhavcopy/'

NOTE: I am logged into windows as an admin and have full rights.注意:我以管理员身份登录 Windows 并拥有完全权限。 How do I pass the rights to the python file write into a directory which will be made by python itself我如何将 python 文件的权限传递到一个由 py​​thon 本身创建的目录中

trading/Bhavcopy. is a directory.是一个目录。 You can't write to a directory.您不能写入目录。 You need to append a file name to save_path .您需要将文件名附加到save_path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM