首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache: Errno 13文件权限被拒绝

Apache: Errno 13文件权限被拒绝
EN

Stack Overflow用户
提问于 2016-06-01 22:13:55
回答 1查看 2.1K关注 0票数 0

我使用AWS EC2运行我的应用程序“神经网络在艺术”。为了发送图像,我部署了一个基于烧瓶+虚拟主机+ apache的网站。在服务器上发送映像后,启动脚本,该脚本将每次迭代打印出来,我希望将其存储在out.txt中

__init__.py:

代码语言:javascript
复制
#...
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'
#...

好吧,我可以通过HTTP上传图像,而不需要在out.txt中写入结果,但是当我这样做时,apache日志显示了以下内容:

代码语言:javascript
复制
[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'

该目录中的所有文件现在都具有777权限。当我尝试用像script.py:这样的简单脚本来写东西的时候

代码语言:javascript
复制
f = open('out.txt', 'w')
f.write('some words')
f.close()

每件事都有用。但是对于apache,没有人知道如何修复它吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-01 22:30:08

问题是apache运行您的代码,其中将有一个不同的工作目录,您不打算将文件写入其中。必须为文件提供完整的路径。

代码语言:javascript
复制
f = open('/path/to/my/out.txt', 'w')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37579631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档