mod_python, multiple calls to PythonAuthenHandler

Steve Holden steve at holdenweb.com
Tue Nov 9 08:36:16 EST 2004


Rune Hansen wrote:

> On Mon, 08 Nov 2004 08:18:45 -0500, Steve Holden wrote:
> 
> 
>>Rune Hansen wrote:
>>
>>
>>>I've posted this question on the mod_python mailing list but didn't get 
>>>much response, so I thought I'd post it here.
>>>
[...]
> 
> Now, I've "solved it" with a single PythonHandler (dropping
> PythonAuthenHandler and publisher):
> 
> def handler(req):
>     if not req.headers_in.get("Authorization",0):
>     	req.err_headers_out["WWW-Authenticate"] = 'Basic realm="Restricted\
>     	area"'
>         raise apache.SERVER_RETURN, apache.HTTP_UNAUTHORIZED
>     meth,auth = req.headers_in.get("Authorization").split(" ") 
>     user,pw = decodestring(auth).split(":")
>     args = dict([(a[0],a[1]) for a in util.parse_qsl(req.args or '')]) 
>     if dbmdbValidate(user,pw,req.server):
> 	return myMethod(req,**args)
>     else:
> 	return apache.HTTP_UNAUTHORIZED
> 
> This seems to do exactly what I want. Guess I should have tried a litle
> harder before posting.
> How ever, I'm still curious to why the PythonAuthenHandler is called for
> each path element.
> 

I'm afraid that's a little beyond me too, but I think you were quite 
within your rights to post the question. Glad you've got past the problem.

Since you're using the publisher handler you might want to consider 
using the methods described in 
http://www.modpython.org/live/current/doc-html/hand-pub-alg-auth.html if 
you haven't already looked at them.

regards
  Steve
-- 
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119



More information about the Python-list mailing list