我正在设置一个flask应用程序,以通过用户界面运行机器学习模型。 我在高级文本(Windows)上运行python3。 我无法将文件保存到目录,除非抛出错误PermissionDenied Errno13
我的文件夹Web_Demo包含Flask中的静态文件,模板和main。
我尝试使用绝对路径名,但是仍然有相同的错误。
app.config["UPLOAD_FOLDER"]= 'D:/Web_Demo/static/'
@app.route('/analysis.html',methods=['GET', 'POST'])
def analysis():
if request.method == "POST":
if request.files:
file=request.files["data"]
filename=secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return redirect(request.url)
return render_template('/analysis.html')
我按下上传按钮后立即收到此错误。这是我选择和上传文件本身的先决条件。
PermissionError: [Errno 13] Permission denied: 'D:/Web_Demo/static/'
我相信我没有写此文件夹的权限。如果是这样,我该如何完成?我已经阅读了有关sudo 775的解决方案,但无法实现或理解它。 任何帮助将不胜感激。
整个回溯如下:
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Utsav Dutta\Anaconda3\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "D:\Web_Demo\main.py", line 34, in analysis
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
File "C:\Users\Utsav Dutta\AppData\Roaming\Python\Python37\site-packages\werkzeug\datastructures.py", line 2799, in save
dst = open(dst, "wb")
PermissionError: [Errno 13] Permission denied: 'D:/Web_Demo/static/'
答案 0 :(得分:0)
尝试使用app.config["UPLOAD_FOLDER"]= './static'
,但不要在结尾加上/
,通常这应该可行。