[mod_python] mptest.py works, other .py files don't

Bas van Dorp bas at vandorp.nu
Wed Jan 19 18:39:01 EST 2005


Hi,

I have the following configuration running:

Apache/2.0.52 (FreeBSD) PHP/5.0.3 mod_python/3.1.3 Python/2.3.4 Server 

I have this apache configuration:

==> httpd.conf:

<Directory /home/www/basd/python>
    AddHandler mod_python .py
    PythonHandler mptest
    PythonDebug On
</Directory>

DocumentRoot "/home/www/"


==> mptest.py:
from mod_python import apache

def handler(req):
    req.write("Hello World!")
    return apache.OK


Guess what? This works :-)) However, when I rename this file to
mptest2.py, I get this:

Mod_python error: "PythonHandler mptest"

Traceback (most recent call last):

  File "/usr/local/lib/python2.3/site-packages/mod_python/apache.py", line 287, in HandlerDispatch
    log=debug)

  File "/usr/local/lib/python2.3/site-packages/mod_python/apache.py", line 454, in import_module
    f, p, d = imp.find_module(parts[i], path)

ImportError: No module named mptest


This was not what I expected. I've read this over and over:
http://www.modpython.org/live/current/doc-html/tut-what-it-do.html

The last paragraph explicitly states that the name of my python script
doesn't matter. I probably missed something... I've tried a lot of
things, but I still get errors. I seem to be able to make mod_python to
execute only the scripts I specify in httpd.conf, and nothing else.
Specifying multiple files in httpd.conf also gives interesting results.
For example: 

==> httpd.conf:
<Directory /home/www/basd/python>
    AddHandler mod_python .py
    PythonHandler mptest
    PythonHandler mptest2
    PythonDebug On
</Directory>

==> mptest.py:
from mod_python import apache

def handler(req):
    req.write("Hello World!")
    return apache.OK

==> mptest2.py:
from mod_python import apache

def handler(req):
    req.write("Hello Universe!")
    return apache.OK


Whether I point my browser to mptest.py or mptest2.py, I get the same
result:

Hello World!Hello Universe!


I don't get it. I would like to tell Apache to parse all .py scripts in
certain directories, just like I do with .php scripts. But how?

Greetings and thanks in advance,

Bas



More information about the Mod_python mailing list