简体   繁体   English

Apache:Errno 13文件权限被拒绝

[英]Apache: Errno 13 file permission denied

I use AWS EC2 to run my application "Neural network in art". 我使用AWS EC2运行应用程序“艺术中的神经网络”。 To send images I deploy a website based on flask + virtualenv + apache. 为了发送图像,我部署了一个基于flask + virtualenv + apache的网站。 After sending the image on the server starts the script, which print each iteration and I want to store it in out.txt 在服务器上发送图像后,启动脚本,该脚本将打印每次迭代,我想将其存储在out.txt中

__init__.py:

#...
def apply_style(image_name, style_name, iterations):
    command = ['"python ~/neural_artistic_style/neural_artistic_style.py', \
            ' --subject ', '/var/www/superapp/superapp/uploads/' + image_name, \
            ' --style ', '/var/www/superapp/superapp/uploads/' + style_name, \
            ' --iterations ', iterations, \
            ' --network ~/neural_artistic_style/imagenet-vgg-verydeep-19.mat"']
    str = ''.join(command)
    network = Popen(str, shell=True, stdout=PIPE)
    stats = []
    for out in network.stdout:
        stats.append(out)
    line = ' '.join(stats)
    return line

@app.route('/upload', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST':
        image = request.files['image']
        style = request.files['style']
        iterations = request.form['iter']
        if file and style:
#Saving images...                
            result = apply_style(image_name, style_name, iterations)
            f = open('out.txt', 'w')
            f.write(result)
            f.close()
            return 'FINISHED'
#...

Well, I can upload image via HTTP without writing result in out.txt, but when I do, apache log shows this: 好吧,我可以通过HTTP上传图像而无需在out.txt中写入结果,但是当我这样做时,apache日志显示了这一点:

[Wed Jun 01 ...] [:error] [pid 2360:tid 14...]     return self.view_functions[rule.endpoint](**req.view_args)
[Wed Jun 01 ...] [:error] [pid 2360:tid 14...]   File "/var/www/superapp/superapp/__init__.py", line 72, in upload
[Wed Jun 01 ...] [:error] [pid 2360:tid 14...]     f = open('out.txt', 'w')
[Wed Jun 01 ...] [:error] [pid 2360:tid 14...] IOError: [Errno 13] Permission denied: 'out.txt'

All files in this directory now have 777 permission. 现在,此目录中的所有文件都具有777权限。 When I try to write something using simple script like script.py: 当我尝试使用简单的脚本(例如script.py:编写内容时script.py:

f = open('out.txt', 'w')
f.write('some words')
f.close()

everithing works. 一切正常。 But with apache it doesn't. 但是用apache却没有。 Has anyone any ideas how to fix it? 有谁知道如何解决它?

The problem is that apache runs your code in which will have a different working directory, one which you do not intend to write the file into. 问题是apache将在您的代码中运行该代码,该代码将具有不同的工作目录,您不打算将该文件写入其中。 You must supply a full path to the file. 您必须提供文件的完整路径。

f = open('/path/to/my/out.txt', 'w')

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

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