我使用AWS EC2运行我的应用程序“神经网络在艺术”。为了发送图像,我部署了一个基于烧瓶+虚拟主机+ apache的网站。在服务器上发送映像后,启动脚本,该脚本将每次迭代打印出来,我希望将其存储在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'
#...好吧,我可以通过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'该目录中的所有文件现在都具有777权限。当我尝试用像script.py:这样的简单脚本来写东西的时候
f = open('out.txt', 'w')
f.write('some words')
f.close()每件事都有用。但是对于apache,没有人知道如何修复它吗?
发布于 2016-06-01 22:30:08
问题是apache运行您的代码,其中将有一个不同的工作目录,您不打算将文件写入其中。必须为文件提供完整的路径。
f = open('/path/to/my/out.txt', 'w')https://stackoverflow.com/questions/37579631
复制相似问题