[mod_python] Multiple calls to authenhandler()

Rune Hansen rune.hansen at scanmine.com
Thu Nov 4 09:51:06 EST 2004


On 4. nov 2004, at 13.07, Jorey Bump wrote:

> Rune Hansen wrote:
>
>>> There has to be a way to control how and when the authenthandler() 
>>> is invoked...?
>
> That function name you mention is incorrect. It must be 
> authenhandler(). Perhaps that is the problem? For more details, see:
>
>  http://www.modpython.org/live/current/doc-html/tut-what-it-do.html
>
>> Problem:
>> For each URI path element a mod_python handler is invoked. This 
>> applies to PythonAuthenHandler, PythonHeaderParserHandler and so on.
>> For me, this is a problem. I would like to avoid re-verifying the 
>> user three times for each request, regardless of verification method.
>> So,
>> a) I've got a miss-configuration which results in multiple calls to 
>> handlers, it's a local error that can be corrected or,
>> b) This is expected behavior and that  there is a technique to avoid 
>> this or,
>> c) This is expected and, for reasons that escapes me, desired 
>> behavior.
>> I'd greatly appreciate any help and suggestion
>
> I don't use PythonAuthenHandler, but if you post the contents of your 
> module, someone might be able to help.

Hi Jorey,
I do appreciate the help and tips you have given me. The 
"authenthandler()" was a typo - the handler in AuthenHandler.py is in 
fact "authenhandler()". Sorry about that.

I've posted a small subset of the files that I'm working on that 
produces the uhm.."error" (btw. my development platform is OS X Client 
10.3.5, Apache/2.0.51 - mod_python 3.1.3 - OS X provided Python2.3) :

httpd.conf:
"""
<VirtualHost *:80>
	ServerName lucene.moonspawn.scanmine.com
	ServerAdmin rune.hansen at scanmine.com
	DocumentRoot /Users/roderik/Sites/Lucene
	ErrorLog logs/lucene_error.log
	CustomLog logs/lucene_access.log common
</VirtualHost>
<Directory "/Users/roderik/Sites/Lucene">
	Options Indexes FollowSymLinks
         AllowOverride None
         Order allow,deny
         Allow from all
         RewriteEngine On
         RewriteBase /
         RewriteRule search.html "SearchHandler.py/search"
	AddHandler mod_python .py
         DirectoryIndex SearchHandler.py
	PythonHandler mod_python.publisher
         PythonAuthenHandler AuthenHandler
         AuthType Basic
         AuthName "Restricted Area"
         require valid-user	
         PythonPath "sys.path+['/Users/roderik/Sites/Lucene']"
	PythonDebug On
</Directory>
"""

AuthenHandler.py
"""
from mod_python import apache

count=0

def authenhandler(req,**args):
     global count

     count +=1
     req.write("AuthenHandler::authenhandler called: "+str(count)+"\n")

     pw = req.get_basic_auth_pw()
     user = req.user

     if user == "mrX" and pw == "1234":
         return apache.OK
     else:
         return apache.HTTP_UNAUTHORIZED
"""

SearchHandler.py
"""
from mod_python import apache

def index(req,**args):
     req.content_type = "text/html"
     req.write("<html><head><title>Search Index 
Page</title><head><body>## 'index' got called once</body></html>")

def search(req,**args):
     req.content_type = "text/html"
     req.write("<html><head><title>Search /search 
Page</title><head><body>## '/search' got called once</body></html>")
"""

Result of:
1) http://lucene.moonspawn.scanmine.com/ =>
	AuthenHandler::authenhandler called: 1
	## 'index' got called once

2) http://lucene.moonspawn.scanmine.com/SearchHandler.py/search =>
	AuthenHandler::authenhandler called: 1
	AuthenHandler::authenhandler called: 2
	## '/search' got called once

3) http://lucene.moonspawn.scanmine.com/search.html => (using 
mod_rewrite)
	AuthenHandler::authenhandler called: 1
	AuthenHandler::authenhandler called: 2
	AuthenHandler::authenhandler called: 3
	## '/search' got called once

regards
/rune


"So as far as I'm concerned, SOAP is not XML, nor is it useful to even a
fraction of the degree to which it is destructive."
- Uche Ogbuji



More information about the Mod_python mailing list