cherrypy with mod_python

6 views
Skip to first unread message

Zed Lopez

unread,
Aug 11, 2006, 3:29:33 PM8/11/06
to cherrypy-users
Hi folks,

I've been working at getting cherrypy running behind mod_python, but
the various web pages I've found on the subject seem to be particular
to their moment in time. Does anyone have a working example with
CherryPy 2.2.1, mod_python 3.1.4, and the current modpython_gateway.py?

Nothing I've tried works with the versions I'm using:

Ubuntu 6.06
Ubuntu 6.06's apache2, python, libapache2-mod-python2.4 packages:
Apache 2.0.55
mod_python 3.1.4
Python 2.4.3

These are locally installed under /var/www/mpch:
CherryPy 2.2.1
modpython_gateway.py rev. 95 from:
http://projects.amor.org/misc/browser/modpython_gateway.py
(modpython_gateway.py is under /var/www/mpch/wsgiref)

I have this in my apache2.conf:

<Directory /var/www/mpch>
PythonPath "['/var/www/mpch']+sys.path"
SetHandler python-program
PythonOption SCRIPT_NAME /mpch
PythonFixupHandler mpchtest::startup
PythonHandler wsgiref.modpython_gateway::handler
PythonOption wsgi.application cherrypy._cpwsgi::wsgiApp
</Directory>

This is mpchtest.py:

import cherrypy
from cherrypy import _cpwsgi

class HelloWorld:
def index(self):
return "Hello world!"
index.exposed = True
wsgi_app = index

def startup(*args):
cherrypy.root = HelloWorld()
cherrypy.server.start()

When I go to http://localhost/mpch/ I get a 500 Internal Server error.
This is the traceback in apache2's error_log (the real IP replaced with
1.1.1.1):

[Fri Aug 11 12:15:32 2006] [error] [client 1.1.1.1] PythonFixupHandler
mpchtest::startup: Traceback (most recent call last):
[Fri Aug 11 12:15:32 2006] [error] [client 1.1.1.1] PythonFixupHandler
mpchtest::startup: File
"/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in
HandlerDispatch\n result = object(req)
[Fri Aug 11 12:15:32 2006] [error] [client 1.1.1.1] PythonFixupHandler
mpchtest::startup: File "/var/www/mpch/mpchtest.py", line 29, in
startup\n cherrypy.server.start()
[Fri Aug 11 12:15:32 2006] [error] [client 1.1.1.1] PythonFixupHandler
mpchtest::startup: File "/var/www/mpch/cherrypy/_cpserver.py", line
72, in start\n Engine.start(self)
[Fri Aug 11 12:15:32 2006] [error] [client 1.1.1.1] PythonFixupHandler
mpchtest::startup: File "/var/www/mpch/cherrypy/_cpengine.py", line
91, in start\n autoreload.main(self._start, freq=freq)
[Fri Aug 11 12:15:32 2006] [error] [client 1.1.1.1] PythonFixupHandler
mpchtest::startup: File "/var/www/mpch/cherrypy/lib/autoreload.py",
line 63, in main\n sys.exit(restart_with_reloader())
[Fri Aug 11 12:15:32 2006] [error] [client 1.1.1.1] PythonFixupHandler
mpchtest::startup: File "/var/www/mpch/cherrypy/lib/autoreload.py",
line 39, in restart_with_reloader\n args = [sys.executable] +
sys.argv
[Fri Aug 11 12:15:32 2006] [error] [client 1.1.1.1] PythonFixupHandler
mpchtest::startup: AttributeError: 'module' object has no attribute
'argv'

cherrypy/lib/autoreload does an 'import sys'. There's not another
sys.py under /var/www/mpch to create any possibility of some weird sys
other than the standard library to have been imported. I really don't
get how sys.argv can be causing an error. Does anyone have any
thoughts? My larger question, though, is the first one: does anyone
have a working example with the current versions? If I'm doing
something fundamentally wrong, I'd rather fix that than solve the
sys.argv problem.

Thanks.

Robert Brewer

unread,
Aug 11, 2006, 3:58:46 PM8/11/06
to cherryp...@googlegroups.com
Zed Lopez wrote:
> I've been working at getting cherrypy running behind mod_python
> ...

> [Fri Aug 11 12:15:32 2006] [error] [client 1.1.1.1] PythonFixupHandler
> mpchtest::startup: File "/var/www/mpch/cherrypy/_cpengine.py", line
> 91, in start\n autoreload.main(self._start, freq=freq)

You can't have autoreload running if you use mod_python. Turn autoreload
off with an entry in your config file:

[global]
autoreload.on = False


Robert Brewer
System Architect
Amor Ministries
fuma...@amor.org

Zed Lopez

unread,
Aug 11, 2006, 7:40:48 PM8/11/06
to cherrypy-users
Thank you! That wasn't my only problem, but it was an essential clue. I
now have it working with:

apache conf:


<Directory /var/www/mpch>
PythonPath "['/var/www/mpch']+sys.path"
SetHandler python-program
PythonOption SCRIPT_NAME /mpch
PythonFixupHandler mpchtest

PythonHandler wsgiref.modpython_gateway::handler
PythonOption wsgi.application cherrypy._cpwsgi::wsgiApp
</Directory>

--


mpchtest.py:
import cherrypy
from cherrypy import _cpwsgi

class HelloWorld:
def index(self):
return "Hello world!"
index.exposed = True
wsgi_app = index

cherrypy.config.update(file = '/var/www/mpch/cherrypy.conf')
cherrypy.tree.mount(HelloWorld())
cherrypy.server.start(init_only = True, server_class = None)
--
cherrypy.conf:
[global]
server.threadPool = 10
server.environment = "production"
server.protocolversion = 'HTTP/1.1'
autoreload.on = False
mount_point = "/mpch"

Zed Lopez

unread,
Aug 14, 2006, 3:58:40 PM8/14/06
to cherrypy-users
Now that I've got it running, my next question is: is there a way to
get access to the apache request option from within CherryPy?
Particularly I'd like to be able to get to the PythonOptions defined in
my apache conf Directory section.

Or is there a better way to get info from the apache conf to my
CherryPy app?

Robert Brewer

unread,
Sep 4, 2006, 7:56:50 PM9/4/06
to cherryp...@googlegroups.com
Zed Lopez wrote:
> Now that I've got it running, my next question is:
> is there a way to get access to the apache request
> option from within CherryPy? Particularly I'd like
> to be able to get to the PythonOptions defined in
> my apache conf Directory section.

Errr...what sort of thing would you put in a PythonOption that wouldn't be better off inside a CherryPy config file?

winmail.dat
Reply all
Reply to author
Forward
0 new messages