Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_wsgi python conf parser

I am set up Flask, a python web micro-framework under apache with mod_wsgi.

The application works fine except python confparser. This throws no error :

parser = ConfigParser.ConfigParser()
parser.read('snati.con')

But when I add :

parser.get('database', 'user')

I got internal server error without anything in the error.log of Apache

I tried also :

file = open("sample.txt")

Same result.

There must be some configuration issues but I can't find it.

My apache conf looks like :

WSGIRestrictStdout Off

<VirtualHost *:80>
    ServerName my.com

    WSGIDaemonProcess myapp user=me group=me threads=5

    WSGIScriptAlias / /home/me/www/myapp.wsgi

    <Directory /home/me/www/myapp >
        WSGIProcessGroup myapp
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

My app.wsgi

#active the python virtualenv for this application
activate_this = '/home/gilles/www/snati/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))


import sys
sys.path.insert(0, '/home/gilles/www/snati/src')
sys.stdout = sys.stderr

from app import app as application

What can possibly be wrong and why can I not get the error in Apache log?

like image 508
gpasse Avatar asked Aug 01 '26 06:08

gpasse


1 Answers

Use absolute paths to files in your Python code, not relative paths.

The current working directory of the process will not be where your application code and files is.

You are not seeing any errors as Flask will not log them if not in debug mode. Setup application to capture them and email them or otherwise record them some how. I don't remember what options Flask has for the latter.

like image 79
Graham Dumpleton Avatar answered Aug 03 '26 19:08

Graham Dumpleton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!