some problems with mod_python

  • Thread starter Bruno Desthuilliers
  • Start date
B

Bruno Desthuilliers

Johan a écrit :
Hi

I have installed and tested this on centos, fedora and freebsd all
give the same problem so I guess I missed some steps.

I have compiled bot apache (2.2.4) and mod_python (3.3.1) according to
the docs and no problem with this.
But when I have made everything about testing mod_python an browse to
http://server/test and there expecting to see "Hello world" I instead
get an index of contents in this directory. If I go to http://server/test/mptest.py
it works. No errors in any log either.

What Have I missed?

The difference between AddHandler and SetHandler in apache's conf.
This I added to httpd.conf
<Directory /opt/site/htdocs/test>
AllowOverride All
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>

Your problem is with Apache configuration, not with mod_python. The
AddHandler directive maps <dirpath>/*.py to your handler. So you have to
call <anythinghere>.py to trigger the desired behaviour. If you want
*any* url under <dirpath> to be handled by mptest, you need to use
SetHandler, not AddHandler.
 
B

Bruno Desthuilliers

Bruno Desthuilliers a écrit :
Johan a écrit :



The difference between AddHandler and SetHandler in apache's conf.
And while we're at it, you also missed the fact that mod_python has it's
own mailing list, where you're more likely to get answers from
mod_python experts (strange as it might be, most of Python web
development doesn't rely on Apache nor mod_python...)
 
J

Johan

Hi

I have installed and tested this on centos, fedora and freebsd all
give the same problem so I guess I missed some steps.

I have compiled bot apache (2.2.4) and mod_python (3.3.1) according to
the docs and no problem with this.
But when I have made everything about testing mod_python an browse to
http://server/test and there expecting to see "Hello world" I instead
get an index of contents in this directory. If I go to http://server/test/mptest.py
it works. No errors in any log either.

What Have I missed?

This I added to httpd.conf
<Directory /opt/site/htdocs/test>
AllowOverride All
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>


this is my mptest.py:
from mod_python import apache

def handler(req):
req.content_type = 'text/plain'
req.write("Hello World!")
return apache.OK

/johan
 
G

Greg Donald

This I added to httpd.conf
<Directory /opt/site/htdocs/test>
AllowOverride All
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>

This is the syntax I have working locally:

# mod_python
<Directory /opt/local/apache2/htdocs/modpython>
AddHandler python-program .py
PythonHandler test
PythonDebug On
</Directory>

In particular my AddHandler directive is different from yours.
 
J

Johan

This is the syntax I have working locally:

# mod_python
<Directory /opt/local/apache2/htdocs/modpython>
AddHandler python-program .py
PythonHandler test
PythonDebug On
</Directory>

In particular my AddHandler directive is different from yours.
If I did understand the docs about the difference between python-
program and mod_python is that the later is the new way, while using
python-program still works.
It does not matter which I use, same result.

/johan
 
G

Graham Dumpleton

Hi

I have installed and tested this on centos, fedora and freebsd all
give the same problem so I guess I missed some steps.

I have compiled bot apache (2.2.4) and mod_python (3.3.1) according to
the docs and no problem with this.
But when I have made everything about testing mod_python an browse tohttp://server/testand there expecting to see "Hello world" I instead
get an index of contents in this directory. If I go to http://server/test/mptest.py
it works. No errors in any log either.

What Have I missed?

This I added to httpd.conf
<Directory /opt/site/htdocs/test>
AllowOverride All
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>

this is my mptest.py:
from mod_python import apache

def handler(req):
req.content_type = 'text/plain'
req.write("Hello World!")
return apache.OK

/johan

You need to look at the Apache documentation for the difference
between AddHandler and SetHandler directives. If you don't want to
read the Apache documentation and learn more about it, at least read:

http://www.dscpl.com.au/wiki/ModPython/Articles/SetHandlerVersusAddHandler

Graham
 
J

Johan

Your problem is with Apache configuration, not with mod_python. The
AddHandler directive maps <dirpath>/*.py to your handler. So you have to
call <anythinghere>.py to trigger the desired behaviour. If you want
*any* url under <dirpath> to be handled by mptest, you need to use
SetHandler, not AddHandler.

Yes, this is what I missed. Using SetHandler instead solved my
problem. Many thanks to the people on the list that pointed that out
for me. (and will use mod_python mailing list in the future as
suggested)

/johan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top