【发布时间】:2014-09-04 18:58:24
【问题描述】:
嗯,我已经配置了我的 Apache、MySql 和 Python。安装了 mod_wsgi 并在我的系统上运行了一个示例 .wsgi “Hello World”应用程序。我的 Flask 应用程序也使用 Flask 的网络服务器在我的 virtualenv 内外执行 python myServer.py 运行,该服务器也配置良好(安装了 flask 和 mysql-python)。
现在我正在尝试部署我的烧瓶应用程序,但我从页面中收到以下错误:
Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
If you think this is a server error, please contact the webmaster.
Error 500
我从 Apache 访问了错误日志,得到了这个:
[Mon Jul 14 19:27:50.692271 2014] [wsgi:error] [pid 56887] [remote ::1:0] mod_wsgi (pid=56887): Target WSGI script '/Applications/XAMPP/htdocs/nudgeAlong/wsgi/myServer.wsgi' cannot be loaded as Python module.
[Mon Jul 14 19:27:50.692387 2014] [wsgi:error] [pid 56887] [remote ::1:0] mod_wsgi (pid=56887): Exception occurred processing WSGI script '/Applications/XAMPP/htdocs/nudgeAlong/wsgi/myServer.wsgi'.
[Mon Jul 14 19:27:50.692411 2014] [wsgi:error] [pid 56887] [remote ::1:0] Traceback (most recent call last):
[Mon Jul 14 19:27:50.692438 2014] [wsgi:error] [pid 56887] [remote ::1:0] File "/Applications/XAMPP/htdocs/nudgeAlong/wsgi/myServer.wsgi", line 4, in <module>
[Mon Jul 14 19:27:50.692535 2014] [wsgi:error] [pid 56887] [remote ::1:0] from myServer import app as application
[Mon Jul 14 19:27:50.692553 2014] [wsgi:error] [pid 56887] [remote ::1:0] File "/Applications/xampp/xamppfiles/htdocs/nudgeAlong/myServer.py", line 2, in <module>
[Mon Jul 14 19:27:50.692633 2014] [wsgi:error] [pid 56887] [remote ::1:0] import MySQLdb
[Mon Jul 14 19:27:50.692658 2014] [wsgi:error] [pid 56887] [remote ::1:0] ImportError: No module named MySQLdb
我的 Wsgi 应用在这里:
import sys
activate_this = '/Applications/XAMPP/htdocs/nudgeAlong/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
sys.path.append('/Applications/xampp/xamppfiles/htdocs/nudgeAlong/')
from myServer import app as application
我的 httpd.conf 虚拟主机部分是:
<VirtualHost *>
ServerName MeuServer
WSGIDaemonProcess myServer threads=5
WSGIScriptAlias /myapp /Applications/XAMPP/htdocs/nudgeAlong/wsgi/myServer.wsgi
<Directory /Applications/XAMPP/htdocs/nudgeAlong/wsgi>
WSGIProcessGroup myServer
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
</VirtualHost>
我的文件夹结构如下:
__主文件夹
____myServer.py
____wsgi/
________myServer.wsgi
____venv/
希望任何人都可以提供帮助。 关于这种情况的奇怪之处在于,错误发生在我的程序的第 2 行,即 import MySQLdb 行,但在此之前我导入了 Flask 并且没有发生错误,所以我可能正在获取库从我的系统...
最后,如果需要,我的 Flask 应用程序:
from flask import Flask, jsonify, render_template, request, make_response, request, current_app
import MySQLdb
from datetime import timedelta
app = Flask(__name__)
db_owen = MySQLdb.connect("localhost","root","","climote_trial")
@app.route('/get_json')
@crossdomain(origin='*')
def get_json():
results = []
c = db_owen.cursor()
c.execute("select date,message_log from trialresults")
jsonresult = c.fetchall()
for x in jsonresult:
dic = {'col1':str(x[0]),'col2':x[1] }
results.append(dic)
return jsonify({ 'results':results });
@app.route('/')
def index():
return render_template('number_1.html')
if __name__ == '__main__':
app.run(debug= True, port=53000)
【问题讨论】:
-
我在数据库访问部分评论了我的代码,并尝试运行应用程序并且它正在运行,此后 Flask 正在运行。问题出在数据库连接上,在 apache 和 python-mysql 驱动程序之间。
-
virtualenv 激活时
pip freeze的输出是什么? -
Flask==0.10.1 Jinja2==2.7.3 MarkupSafe==0.23 MySQL-python==1.2.5 Werkzeug==0.9.6 itsdangerous==0.24 wsgiref==0.1.2跨度>
标签: mysql apache flask mod-wsgi