Home:ALL Converter>Running CherryPy under mod_wsgi

Running CherryPy under mod_wsgi

Ask Time:2012-12-03T13:02:58         Author:WilHall

Json Formatter

I am trying to get a CherryPy app running under apache2/mod_wsgi on ubuntu. I am following the tutorial outlined here, and my config is almost identical. When visiting the root of the site, I receive a 500 Internal Server Error. The only error in the log is:

[Mon Dec 03 04:43:06 2012] [error] [client 64.189.251.239] Premature end of script headers: index.py

I have tried several variations to the tutorial, but I am not receiving any significant errors. Any ideas?

My Apache VirtualHost:

...
    WSGIScriptAlias / /var/www/example.com/uba/index.py
DocumentRoot /var/www/example.com/uba/
<Directory />
    Options +ExecCGI Indexes FollowSymLinks
    AllowOverride All
</Directory>

<Directory /var/www/example.com/uba/>
    Options +ExecCGI -Indexes -FollowSymLinks -MultiViews
    WSGIApplicationGroup %{GLOBAL}
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>
...

My index.py script:

#!/usr/bin/python

import sys
sys.stdout = sys.stderr

import atexit
import threading
import cherrypy

cherrypy.config.update({'environment': 'embedded'})

if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
    cherrypy.engine.start(blocking=False)
    atexit.register(cherrypy.engine.stop)

class Root(object):
    def index(self):
        return 'Hello World!'
    index.exposed = True

application = cherrypy.Application(Root(), script_name=None, config=None)

UPDATE #1:

Running this very basic wsgi application produces the exact same error:

#!/usr/bin/python

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

Author:WilHall,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/13677431/running-cherrypy-under-mod-wsgi
yy