使用Flask访问Python3.6上文件夹的权限被拒绝
编辑:完全忽略此问题。这是一个文件系统问题 每当我试图打开使用Flask访问Python3.6上文件夹的权限被拒绝,flask,file-permissions,python-3.6,Flask,File Permissions,Python 3.6,编辑:完全忽略此问题。这是一个文件系统问题 每当我试图打开posts文件夹时,我都会收到一个错误: Traceback (most recent call last): File "C:\Python36-32\lib\site-packages\flask\app.py", line 1997, in __call__ return self.wsgi_app(environ, start_response) File "C:\Python36-32\lib\site-pack
posts
文件夹时,我都会收到一个错误:
Traceback (most recent call last):
File "C:\Python36-32\lib\site-packages\flask\app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Python36-32\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "C:\Python36-32\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Python36-32\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Python36-32\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python36-32\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python36-32\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python36-32\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Python36-32\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python36-32\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\vikas\Projects\blg\main.py", line 19, in index
return render_template("index.html", newest_post=find_recent_post())
File "C:\Users\vikas\Projects\blg\main.py", line 12, in find_recent_post
with open(str(find_recent_post_name())) as post:
PermissionError: [Errno 13] Permission denied: 'posts/'
My main.py文件:
from flask import Flask
from flask import render_template
app = Flask(__name__)
def find_recent_post_name():
import glob
posts = glob.glob("posts/")
return posts[len(posts) - 1]
def find_recent_post():
with open(str(find_recent_post_name())) as post:
newest_post = post.readlines()
return newest_post
@app.route("/")
def index():
return render_template("index.html", newest_post=find_recent_post())
if __name__ == '__main__':
app.run(debug=True)
我的Python版本是v3.6.1和v1.12.0
编辑:调试代码和使用PowerShell似乎很有效。这不是flask的问题。您可以更改文件夹
/posts/
上的权限,也可以作为具有读取权限的用户运行flask
$ chmod 755 <folder names>
以管理员身份运行或以已具有访问权限的用户身份运行flask。请注意,您应该在部署时添加相同的设置。因此uwsgi
或gunicron
的工作人员,或者无论您如何在部署时运行应用程序,都应该使用相同的凭据运行
请注意,您的用户
应同时具有读取
或4
访问权限以读取文件内容,并具有执行
或1
访问权限以能够将cd
放入其中
$ sudo python main.py