Terry MacDonald
terry.macdonald at dsl.pipex.com
Thu May 20 12:54:20 EDT 2004
On Thu, 2004-05-20 at 08:51, Volodya wrote: > On Wed, May 19, 2004 at 06:56:02PM +0100, Terry MacDonald wrote: > > On Wed, 2004-05-19 at 18:27, Jorey Bump wrote: > > > I don't need to use the suffix. My httpd.conf looks like this (Debian > > > Woody: apache 1.3.26, mod_python 2.7.8): > > > > > > <Directory /var/www/documentroot> > > > AddHandler python-program .py > > > PythonHandler mod_python.publisher > > > PythonDebug On > > > </Directory> > > > > > > I can access function foobar in app.py like this: > > > > > > http://www.example.com/app/foobar > > > > > > Well something is different because with this config (i'm not an apache > > expert): > > > > (Using Fedora Core 1, apache 2.0.48 and mod_python 3.1.3) > > > > PythonDebug on > > > > <Directory "/var/www/python"> > > PythonPath "['/var/www/python']+sys.path" > > AddHandler mod_python .py > > PythonHandler mod_python.publisher > > Options None > > AllowOverride None > > Order allow,deny > > Allow from all > > </Directory> > > > > my foobar in app.py called as http://localhost/app/foobar gives a 'Not > > Found' error while http://localhost/app.py/foobar works fine. > > > > This is an ongoing bugbear for me: dropping the .py. Can anyone explain > > this odd behaviour, Grisha? > > > > Under Apache 2 , you MUST use "SetHandler mod_python". By this, you're > telling Apache to direct all requests (in this dir) to mod_python > module. And by specifying "PythonHandler mod_python.publisher" , your're > telling mod_python to use publisher handler. > > So when you're accessing http://localhost/app/foobar , Apache directs > this request to mod_python. Mod_python uses publisher-handler logic to > process this request. This page explains traversal logic: > > http://www.modpython.org/live/current/doc-html/hand-pub-alg-trav.html > > Quote : > If req.filename is empty, the module name defaults to "index". > > So publisher-handler will try to import index.py module , and execute > its foobar() function. > > In your case : > You have no SetHandler directive , so Apache directs only *.py > requests to mod_python module. > > So: > http://localhost/app.py/foobar , passes to mod_python > > and > > http://localhost/app/foobar is served by Apache itself wich > produces 404 error. > > > > P.S. As far as i know, SetHandler/AddHandler behavior > is slightly different in Apache 1.3 and Apache 2. If I do this in http.conf PythonDebug on <Location /test> SetHandler mod_python PythonHandler mod_python.publisher </Location> If in the test directory I have a file index.py containing a function index() and I direct my browser to http://localhost/test I get this: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "/usr/lib/python2.2/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/usr/lib/python2.2/site-packages/mod_python/publisher.py", line 98, in handler path=[path]) File "/usr/lib/python2.2/site-packages/mod_python/apache.py", line 454, in import_module f, p, d = imp.find_module(parts[i], path) ImportError: No module named test The publisher is treating the '/test' part of the URI as a module! So what am I doing wrong? -- Terry Registered Linux User # 311806 www.taumu.com
|