1

所以我从 github 上的 OS quickstart 在 OS 中创建了一个烧瓶应用程序。该应用程序在我的本地系统上运行良好。当我将应用程序推送到它构建的操作系统时,我在浏览器中收到错误 500。

任何想法或帮助将不胜感激。

以下是应用程序文件的源代码:

#!/usr/bin/python import os

virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass

from run import app as application

这是 run.py 文件的源代码

from app import app 
app.run(debug = True)

以下是日志中的错误(删除了我网站的 HASH ID):

[Sun Aug 05 15:46:08 2012] [error] * Running on http://127.0.0.1:5000/
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] mod_wsgi (pid=28484): Target WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application' cannot be loaded as Python module. 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] mod_wsgi (pid=28484): Exception occurred processing WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application'. 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] Traceback (most recent call last): 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application", line 13, in <module> 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] from run import app as application 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/run.py", line 2, in <module> 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] app.run(debug = True) 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Flask-0.9-py2.6.egg/flask/app.py", line 739, in run 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] run_simple(host, port, self, **options) 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Werkzeug-0.8.3-py2.6.egg/werkzeug/serving.py", line 613, in run_simple 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] test_socket.bind((hostname, port)) 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "<string>", line 1, in bind 
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] error: [Errno 13] Permission denied 
[Sun Aug 05 15:46:09 2012] [error] * Running on http://127.0.0.1:5000/
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] mod_wsgi (pid=31302): Target WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application' cannot be loaded as Python module. 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] mod_wsgi (pid=31302): Exception occurred processing WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application'. 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] Traceback (most recent call last): 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application", line 13, in <module> 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] from run import app as application 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/run.py", line 2, in <module> 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] app.run(debug = True) 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Flask-0.9-py2.6.egg/flask/app.py", line 739, in run
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] run_simple(host, port, self, **options) 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Werkzeug-0.8.3-py2.6.egg/werkzeug/serving.py", line 613, in run_simple 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] test_socket.bind((hostname, port)) 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "<string>", line 1, in bind 
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] error: [Errno 13] Permission denied
4

3 回答 3

2

在 mod_wsgi 下托管时,您不应该尝试运行内置开发服务器的 Flask。返回并检查 Flask 中的 mod_wsgi 文档,了解您打算做什么。

http://flask.pocoo.org/docs/deploying/mod_wsgi/

于 2012-08-06T00:22:56.787 回答
2

所以我终于弄清楚我的代码出了什么问题。我的 run.py 文件中缺少一行,因此不正确的文件如下所示:

不正确的文件:

from app import app
app.run()

这是更正后的工作文件:

from app import app
if __name__ == "__main__": #Need this line for Openshift
    app.run()

部署到 Apache 等生产服务器时显然需要 if 语句

于 2012-08-06T14:46:43.227 回答
1

您是否检查过以下烧瓶网站的描述:http: //flask.pocoo.org/docs/deploying/mod_wsgi/#working-with-virtual-environments

问题:应用程序提供权限错误可能是由于您的应用程序以错误的用户身份运行引起的。确保应用程序需要访问的文件夹具有正确的权限设置,并且应用程序以正确的用户身份运行(WSGIDaemonProcess 指令的用户和组参数)

于 2012-08-06T01:01:49.847 回答