[mod_python] addhandler or sethandler

Graham Dumpleton grahamd at dscpl.com.au
Tue May 16 22:10:31 EDT 2006

David Bear wrote ..
> I'm trying to better understand the directive semantics. So, I created
> 2 .htaccess files.
> the mpt.py file is the same. However I get different results between
> each .htaccess file.
> .htaccess
> SetHandler mod_python
> PythonHandler mod_python.publisher
> PythonDebug On

For SetHandler, any request against the directory will be processed
by mod_python which in turn will bump request through to mod_python.publisher.

> ---
> The above file produces an error when viewing mpt.py:
> Mod_python error: "PythonHandler mod_python.publisher"
> Traceback (most recent call last):
>   File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line
> 299, in HandlerDispatch
>     result = object(req)
>   File "/usr/lib64/python2.4/site-packages/mod_python/publisher.py",
> line 98, in handler
>     path=[path])
>   File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line
> 457, in import_module
>     module = imp.load_module(mname, f, p, d)
>   File "/work/servers/www/htdocs/apep/index.py", line 22
>     return "Falling through to main "
> SyntaxError: 'return' outside function

This looks like an indentation problem in your code file.

> However, the below htaccess file produces the expected result, it
> executes the python function, which is:
> from mod_python import apache
> def handler ( req ):
>   req.content_type = "text/plain"
>   req.send_http_header()
>   req.write( "mod python test \n hello world" )
>   return apache.OK
> .htaccess
>  AddHandler python-program .py
>  PythonHandler mpt
>  PythonDebug On

Only requests for which URL resolves to physical file with a .py extension
which be processed by mod_python which will in turn bump request
through to "mpt" handler.

Note that I intentionally say extension of physical file URL mapped to
as multiview matching rules can come into play. See link down further.

Note that "python-program" is same as saying "mod_python" in
mod_python 3.X. Only "python-program" was accepted in mod_python 2.X.

> I hate to bug this group but can someone explain the difference?

For some information, see discussion around:



More information about the Mod_python mailing list