[mod_python] PythonHandler does not appear to append directory to import path

Gerrat Rickert grickert at coldstorage.com
Mon Sep 8 17:42:33 EST 2003


I'm using mod_python 3.03, apache 2.047, and python 2.2.3 on a win2K machine
& am trying to use the publisher handler.  The problem is when I try to add
an additional handler via:

req.addhandler("PythonHandler", testModule, directory_to_append_to_sys_path)

The error I am getting is:

Mod_python error: "PythonHandler testModule"

Traceback (most recent call last):

  File "D:\Python22\lib\site-packages\mod_python\apache.py", line 340, in
HandlerDispatch
    module = import_module(module_name, config)

  File "D:\Python22\lib\site-packages\mod_python\apache.py", line 516, in
import_module
    f, p, d = imp.find_module(parts[i], path)

ImportError: No module named testModule



Looking through the HandlerDispatch function of apache.py, the relevant code
is:

if config.has_key("PythonPath"):
...
else:
    dir = hlist.directory
    if dir and (dir not in sys.path):
        sys.path[:0] = [dir]


This code doesn't appear to add my directory
(directory_to_append_to_sys_path) to the sys.path if I have "PythonPath" in
my httpd.conf file.  Importing my module fails because of this.  I'm not
sure if this is just a misunderstanding on my part or has already been
addressed (in which case I apologize for posting).  As far as I can see, the
"else" portion of this statement should be executed regardless of whether
PythonPath is in the config file or not.  Can anyone else confirm this?

Thanks,
Gerrat Rickert




More information about the Mod_python mailing list