[mod_python] Using mod_python pythonauthenhandler with PSO

Roy S. Rapoport mod_python at ols.inorganic.org
Thu Jun 26 01:04:02 EST 2003

Hey guys,

Anyone have any experience integrating mod_python with Python Service

I've got a problem where if I'm dealing with an authenhandler, I end up
with an error message that says:
Mod_python error: "PythonLogHandler pso.modpython::cleanup"

Traceback (most recent call last):

"/usr/local/Python/lib/python2.2/site-packages/mod_python/apache.py", line
332, in HandlerDispatch
    result = object(req)

  File "/usr/local/Python/lib/python2.2/site-packages/pso/modpython.py",
line 36, in cleanup

  File "/usr/local/Python/lib/python2.2/site-packages/pso/service.py", line
52, in cleanup

AttributeError: 'mp_request' object has no attribute 'pso'

I'm pretty sure this is related to authenhandler because if you then try to
access a resource under this directory -- which means that now you're not
going through authenhandler -- it works.

My script looks like this:

from mod_python import apache

def foo(req):
		req.pso().session['visits'] +=1
		req.pso().session['visits'] =1
	f = "Hello World!  ~ Your visit number: %(visits)d ~ Try Reload !" %  req.pso().session
	return f

def authenhandler(req):
	user = req.user
	pw = req.get_basic_auth_pw()

	if (user == "foo" and pw == "bar"):
		return apache.OK
		return apache.HTTP_UNAUTHORIZED

my .htaccess looks like this:
AddHandler python-program .py
PythonHandler mod_python.publisher
pythonauthenhandler quicktest
PythonFixupHandler pso.modpython::fixup
PythonLogHandler pso.modpython::cleanup
PythonDebug On
AuthType Basic
AuthName "Enter your email username and password"
require valid-user

To test this:
Go to http://www.inorganic.org/~rsr/python2/quicktest.py/foo
Authenticate with foo/bar
This should pause for a moment and then give you the error message.
If you hit 'reload,' you don't go through authenhandler (since you're
already authenticated) and you get the correct output.



More information about the Mod_python mailing list