好吧,我已经配置了我的Apache,MySql和Python。安装了mod_wsgi并在我的系统上运行了一个示例.wsgi“Hello World”应用程序。我的Flask应用程序也运行使用Flask的web服务器在我的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>
我的文件夹结构如下:
__ mainfolder
____ myServer.py
____ WSGI /
________ myServer.wsgi
____ VENV /
希望任何人都可以提供帮助。 关于这种情况的奇怪之处在于错误发生在我的程序的第2行,导入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)
答案 0 :(得分:1)
<强>解决强>: 如果我错了,任何人都会纠正我。我相信问题在于,当你安装mysql-python时,你需要连接&#34;您的Python解释器的内部MySql文件。所以,当我安装它时,它将我的MySql连接到我的Python。之后我安装了XAMPP,它拥有自己的MySql。一切都发生了冲突,我试图以多种方式解决它,但都没有奏效。我从中学到的两件事是你必须决定是否要使用像MAMP,XAMPP这样的东西,或者自己安装网络服务器,数据库和驱动程序的基本方法。另一件重要的事情是那三个 - 网络服务器,数据库和编程语言解释器 - 必须具有相同的架构(32或64位)。
最后我决定重新安装所有内容,这是我使用Mac OS X Mavericks采取的程序:
安装MySql翻新我的符号链接
sudo rm /usr/lib/libmysqlclient.18.dylib
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
安装mysql-python(注意设置正确的路径)
export PATH = $ PATH:/ usr / local / mysql / bin
sudo pip install mysql-python
安装了Apache的网站教程
已安装的mod_wsgi设置了Apache和我的Python解释器的正确路径
./ configure --with-apxs = / path / to / apache / bin / apxs \ --with-python = / path / to / bin / python
之后我将我的应用程序在Flask的网络服务器中运行。并使用了我的问题代码中的相同配置,一切正常。