2017-07-03 200 views
0

每当我试图打开posts文件夹Python3.6到文件夹,我得到一个错误:权限被拒绝访问与瓶

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/' 

我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和Flask v1.12.0

编辑:调试代码和使用PowerShell似乎工作。

+0

给运行该应用程序的用户访问该文件夹。这是一个文件系统的事情,而不是Flask的事情。 – davidism

回答

0

烧瓶不是问题。您可以更改文件夹/posts/上的权限,也可以将烧瓶作为拥有read访问权限的用户运行。

$ chmod 755 <folder names> 

授予访问权限谁跑的烧瓶应用的用户,或者你可以使用:

$ sudo python main.py 

admin运行或运行烧瓶谁已经拥有访问权限的用户。并注意您应该在部署时添加相同的设置。因此uwsgigunicron的工作人员或者在部署上运行应用程序应该使用相同的凭据运行。

请注意,您应该user兼得read4访问读取文件内容的,并有execute1访问能够cd进去。