Ubuntu中的Flask-如何允许Flask访问保留文件 [英] Flask in Ubuntu - How to allow Flask to access a reserved file

查看:110
本文介绍了Ubuntu中的Flask-如何允许Flask访问保留文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Flask能够打开Apache错误日志(/var/logs/apache2/error.log)并以保留的路线向我展示.但是服务器不喜欢它,因为Flask没有读取该文件的权限.错误显示如下:

I'd like Flask to be able to open the Apache error log (/var/logs/apache2/error.log) and show it to me in a reserved route. However the server does not like it as Flask does not have permission to read that file. The error is shown below:

with open('/var/log/apache2/error.log', 'r') as errorlog_file:
IOError: [Errno 13] Permission denied: '/var/log/apache2/error.log'

这是Flask代码:

@app.route('/errorlog', methods=['GET'])
def errorlog():    
    with open('/var/log/apache2/error.log', 'r') as errorlog_file:
        errorlog_text = errorlog_file.read()           
        return errorlog_text

最好的解决方法是什么?

What is the best workaround?

有关更多信息,我在Ubuntu 14.04的Digital Ocean中安装了flask应用程序,该应用程序完全根据

For further info, I have the flask app in Digital Ocean on Ubuntu 14.04, deployed exactly according to this tutorial

我用于执行所有工作的用户具有sudoer权限,并且flask位于virtualenv中

The user that I use to do all the work has sudoer permissions and flask is in a virtualenv

推荐答案

运行该应用程序的用户无权查看该文件.最终,只有一种解决方案:更改权限.将运行Flask应用程序的用户添加到可以查看日志文件的组中,或者更改日志文件的权限,以便其他人可以读取它.

The user that runs the app doesn't have permission to view the file. Ultimately, there is only one solution: change the permissions. Either add the user that runs the Flask app to the group that can view the log file, or change the permissions on the log file so that others can read it.

这篇关于Ubuntu中的Flask-如何允许Flask访问保留文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆