1

Well, I already configured my Apache, MySql and Python. Installed the mod_wsgi and ran a example .wsgi "Hello World" application on my system. My Flask application is also running using Flask's webserver executing python myServer.py inside and outside my virtualenv that is also well configured (flask and mysql-python installed).

Now I'm trying to deploy my flask application and I'm getting the following error from the page:

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

I went to the Error Log from Apache and I got this:

[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

My Wsgi application here:

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

My httpd.conf virtual host part is:

<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>

My folders are structured like this:

__mainfolder

____myServer.py

____wsgi/

________myServer.wsgi

____venv/

Hope anyone can help. The curious thing about the situation is that the error is occuring in line 2 of my program, the import MySQLdb line, but before that I imported Flask and no error occured, so I'm probably getting the libraries from my system...

To finish, my Flask app if needed:

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)
3
  • I commented my code in the DB access part and just tried to run the app and it's running, henceforth Flask is working. The problem is on the DB connection, something between apache and the python-mysql driver. Commented Jul 14, 2014 at 19:00
  • What is the output of pip freeze when the virtualenv is active? Commented Jul 15, 2014 at 2:21
  • 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 Commented Jul 15, 2014 at 11:41

1 Answer 1

1

SOLVED: Anyone correct me if I'm wrong.I believe the problem was that when you install mysql-python you "connect" your internal MySql files with your Python interpreter. So, when I installed it, it was connecting my MySql to my Python. After that I installed XAMPP, that has it's own MySql. Everything went in conflict, I tried to solve it in many ways, none of them worked. Two things that I learned from it is that you have to decide if you are going to use something like MAMP, XAMPP or do it the basic way installing the webserver, the database and the driver all by yourself. Another thing that is important is that those three - webserver,DB and programming language interpreter - must have the same architecture (32 or 64 bits).

Finally I decided to reinstall everything, here is the procedure I took using Mac OS X Mavericks:

  1. Cleaning the mess: I deleted XAMPP ( take care to move you application files before delete it, I almost lost all my code )
  2. Uninstalled MySQL following this link
  3. Uninstall mysql-python: sudo pip uninstall mysql-python
  4. Installed MySql renovating my symbolic links

    sudo rm /usr/lib/libmysqlclient.18.dylib

    sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

  5. Installed mysql-python (taking care to set the right paths)

    export PATH=$PATH:/usr/local/mysql/bin

    sudo pip install mysql-python

  6. Installed Apache following it's website tutorial

  7. Installed mod_wsgi setting the right paths to Apache and to my Python interpreter

    ./configure --with-apxs=/path/to/apache/bin/apxs \ --with-python=/path/to/bin/python

    After that I made my application work in the Flask's webserver. And used the same configuration that is in the code of my question and everything worked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.