[mod_python] confused about add_handler

Gregory (Grisha) Trubetskoy grisha at modpython.org
Fri Feb 8 13:32:20 EST 2002


Hmm - I don't see anything wrong with this, it should work. Are you able
to get normal authentication going with an .htpasswd file for the same
directory?

Grisha

On Fri, 8 Feb 2002, Lewis Bergman wrote:

> I am having difficulty. I am sure the root of the problem is my own stupidity
> but after 2 days of trying I can't seem to resolve this issue. No errors
> appear in the log. It just seems to ignore my handler and shows an index of
> the directory. I assume from the manual covering this section that this might
> mean the handler is invalid, but I don't think so. I read the "food for
> thought" (the one that says the name of the file doesn't matter) paragraph
> and thought maybe this is it. I don't believe so because that is an externel
> request detail and this is an internal deal.
>
> Here is the situation:
> auth.py is set as the authen handler like so
> <Directory /var/www/html/ispmgr>
>   AddHandler python-program .py
>   PythonHandler mod_python.publisher
>   PythonAuthenHandler auth
>   AuthType Basic
>   AuthName "Restricted Area"
>   require valid-user
>   PythonDebug On
> </Directory>
>
> As you can see I am trying to use the publisher.
>
> auth.py looks like this:
> from mod_python import apache
> def authenhandler(req):
> 	"""Provide the correct page for the privilege of user."""
>
> 	pw = req.get_basic_auth_pw()
> 	user = req.connection.user
> 	if user == "admin" and pw == "admin":
> 		req.add_handler("PythonHandler", "setup::admin")
> 		return apache.OK
> 	if user == "operator" and pw == "operator":
> 		req.add_handler("PythonHandler", "setup::operator")
> 		return apache.OK
> 	if user == "user" and pw == "user":
> 		req.add_handler("PythonHandler", "setup::user")
> 		return apache.OK
> 	else:
> 		return apache.HTTP_UNAUTHORIZED
>
> Later I will replace the statements with db calls (if I can ever get this
> working)
>
> I think this means it should look for the setup file, try to instantiate it
> as setup and try to invoke the method admin. I am sure my logic must be way
> off here.
> In case it is required, here is setup.py
> class setup:
>
> 	def _frame(frameLeft, frameRight):
> 		"""Sets up frames.
>
> 		frameleft and frameright will be replaced by the correct menu function.
> 		"""
> 		html = """\
> 			<html>
> 			<head>
> 				<title>ISPMgr</title>
> 				<link rel=stylesheet type="text/css" href="ispmgr.css" title="stylesheet">
> 			</head>
> 			<frameset cols="20%%,*">
> 				<frame src="%s" name="menu">
> 				<frame src="%s" name="main">
> 			</frameset>"""% (frameLeft, frameRight)
>
> 		return html
>
>
> 	def admin():
> 		"""Provide all options to admin users."""
> 		r = _frame('menu.admin', 'main.customer')
> 		return r
>
> Do all the handlers have to appear in the same file? (auth.py)
> Lost and hopeless, please help.
> --
> Lewis Bergman
> Texas Communications
> 4309 Maple St.
> Abilene, TX 79602-8044
> 915-695-6962 ext 115
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
>




More information about the Mod_python mailing list