[mod_python] mod_python doesn't parse python scripts

Graham Dumpleton grahamd at dscpl.com.au
Tue May 24 18:30:30 EDT 2005


Graham Dumpleton wrote ..
> As pointed out by others don't use "test.py". Further, don't use 
> "Location"
> directive, use the "Directory" directive instead, like the referenced
> article says to use. Using "Location" can introduce other issues and 
> should
> be avoided if you are new to mod_python.

I was on the way out the door when writing this response, not that I
have more time I'll explain why it wasn't working.

When you use the "Directory" directive with a physical directory as the
path, that path will be added into the Python sys.path. When mod_python
looks for the module you specify with the PythonHandler directive it
will therefore be able to find the module if it is actually located in that
physical directory.

If instead you use the "Location" directive, the path is actually the URL
path and not a physical directory. As Python requires a physical directory
for the sys.path search path, it can't use that path in any way. This means
that when it searches for the module you specify, it will not look at your
copy. Because in this case you didn't call your module "mptest" as the
documentation says to and instead used "test", it found the standard
Python module called "test" instead. Although it was able to load that
module, there was no "handler()" method defined within it and thus you
would most likely have got an error or an empty response (can't remember
which).

Therefore, use the "Directory" directive in preference to the "Location"
directive. If for some reason you must use the "Location" directive, you
would need to have also set the "PythonPath" directive to extend the
sys.path manually to include the directory where your module is installed.
Using the "Location" directive can cause other problem as though such
as Session objects not working. This is because the Session object in
the current mod_python versions rely on being used within a "Directory"
directive so it can determine the physical path associated with it. You
would need to set "ApplicationPath" explicitly if you wanted to use the
"Location" directive and also use Session objects.

Note that if you use .htaccess files as was recommended to be used in
the article for a first attempt at getting things working, there is an
implicit use of the "Directory" directive and thus the directory the .htaccess
file was in would have been automatically added to sys.path and the
module would have been found.

Anyway, hope this helps. I'll update the referenced article yet again with
warnings about not using a name other than "mptest" and especially
not "test". Also warnings about not using "Location".

As to the warning about the "PythonHandler" command, I am not sure
in what order Apache evaluates the configuration, but it may be caused
by the directive being used in the configuration file before the mod_python
module has been loaded into Apache.

Graham

> On 24/05/2005, at 11:34 PM, Fabiano Sidler wrote:
> 
> > Thank you for answering that quickly!
> >
> > Graham Dumpleton wrote:
> >> Read:
> >>   http://www.dscpl.com.au/projects/vampire/articles/modpython-001.html
> >> "PythonRequestHandler" doesn't work because it isn't a valid directive
> >> name.
> >
> > Sorry, but doesn't work here:
> >
> >    <Location /py>
> > 	    AddHandler python-program .py
> > 	    PythonHandler test
> > 	    PythonDebug On
> >    </Location>
> >
> >    [Tue May 24 14:53:47 2005] [notice] mod_python: (Re)importing 
> > module 'test'
> >
> > Meanwhile, httpd does start without any errors, but when try stopping
> > or
> > restarting it, I got the following message:
> >
> >    Invalid command 'PythonHandler', perhaps mis-spelled or defined by
> > a module
> >    not included in the server configuration
> >
> > Strange, isn't it?
> >
> > Greetings,
> > Fips
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://mailman.modpython.org/mailman/listinfo/mod_python
> 
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python


More information about the Mod_python mailing list