[mod_python] publisher handler not working on FreeBSD, Apache 1.3 and modpython 2.7

Jorey Bump list at joreybump.com
Sun Mar 26 12:33:58 EST 2006


Graham Dumpleton wrote:
> 
> On 26/03/2006, at 8:45 AM, Alberto Ruiz wrote:
> 
>> So you are saying that I have to modify my calls to my python scrypts to
>> be propman.py/index , instead of just propman.py, right?

Yes.

> It should be sufficient to use "propman.py" even if you were to use
> mod_python.publisher as it will fallback to calling "index()".

This is not true with mod_python 2.7.10. As the OP states, it returns a 
404 error when calling the script directly. Calling the script with a 
trailing slash returns this error:

Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

   File "/usr/lib/python2.1/site-packages/mod_python/apache.py", line 
193, in Dispatch
     result = object(req)

   File "/usr/lib/python2.1/site-packages/mod_python/publisher.py", line 
90, in handler
     if func_path[-1] == ".":

IndexError: string index out of range

See this for more information:

http://www.modpython.org/live/mod_python-2.7.8/doc-html/hand-pub-alg-trav.html

I believe someone has posted a patch to add more modern index traversal 
to 2.7.x versions of mod_python. You'll need to search the archives.

My recommendation to Publisher beginners is to avoid using modules named 
  index.py and index() functions until they thoroughly understand how 
mod_python works. Index traversal is a special case in 3.x, and it's 
nearly impossible to understand coming from a different background. The 
documentation can also be misleading (note that this is for mod_python 
3.x, not 2.x!):

http://www.modpython.org/live/current/doc-html/hand-pub-alg-trav.html

>> The version of modpython in my old system was 2.7.10, so I assumed that
>> they weren't that many changes.

They are very different in some key ways, enough to cause you grief. Be 
sure to consult the right documentation.

>> So is there a way to change the call to my scripts so I don't to
>> append /index ?
> 
> If you have control over this box, I would highly recommend you upgrade
> to Apache 2.2 and mod_python 3.2.8.

If this isn't possible, you can plan ahead and reorganize things a bit. 
Designate a directory that will only serve modules via Publisher. Then 
always set an explicit function to be the target. So if you set up an 
app/ directory, and use SetHandler instead of AddHandler, your URL might 
look like this:

  http://host/app/propman/foo

Where foo() is the function that returns your content. You don't have to 
have an index() function in your module. Yes, people will get strange 
errors if they try to go places they shouldn't, but that'll learn 'em. :)

I use this approach on some Debian Woody systems I still have in 
production, and it works fine. When you move to an Apache 2.x/mod_python 
3.x system, you can start to take advantage of the convenient, but 
totally unnecessary, index traversal capabilities.



More information about the Mod_python mailing list