mod_python apache configuration issues

digidalmation dgargan at
Thu Oct 21 03:57:23 CEST 2004

David Fraser wrote:
> digidalmation wrote:
>> Hello all.  I've been trying to get my linux server to run mod_python.
>> It's a Mandrake 10 linux box, and apache/mod_python are installed from 
>> rpms.
>> apache2-mod_python-2.0.48_3.1.3-1mdk
>> apache2-2.0.48-6mdk
>> The rpm installed the python module as:
>> /usr/lib/apache2-extramodules/
>> And added a config file for apache:
>> /etc/httpd/conf.d/16_mod_python.conf
>> The apache config files contained the following before my modifications:
>> <IfDefine HAVE_PYTHON>
>>   <IfModule !mod_python.c>
>>     LoadModule python_module    extramodules/
>>   </IfModule>
>> </IfDefine>
>> <IfModule mod_python.c>
>> </IfModule>
>> Now after reading the docs installed into /usr/share/doc for mod_python
>> and going through the directions at, I've also changed the
>> config file to add a few lines to one of the directives:
>> <Directory /var/www/html>
>>     Options -Indexes FollowSymLinks MultiViews
>>     AllowOverride All
>>     AddHandler mod_python .py
>>     PythonHandler mptest
>>     PythonDebug On
>> </Directory>
>> Now when I put the url into a browser:
>> I get a popup from the browser because it doesn't know how to handle
>>, and it asks what you want to do with the file (open it with
>> an application, save it to disk, etc).  I can choose to open the file
>> with a text editor, and all it shows is the text "hello world".
>> That's the output of the script....  apache isn't feeding the
>> browser the code from the, only the output.  (Otherwise when I
>> open it in a text editor I'd see the entire script.
>> Contents of the script:
>> from mod_python import apache
>> def handler(req):
>>         req.write("Hello World!")
>>         return apache.OK
>> I'm not a python developer, but have been working with Linux and Apache
>> for a number of years.  I'm not sure where to go from here.  It appears
>> that the script gets compiled - there is a mptest.pyc file in the
>> directory now.  Why is it sending my browser the file with the
>>  stdout of the script?
>> Thanks in advance.  Any help on this is appreciated.
>> Dave
> This is working properly, all you want to do is set the content type so 
> that your browser can understand it:
> req.content_type = "text/plain"
> or something like that should do it.
> David

David, you steered me in the right direction!  I just added this to my 
apache config file, and voila... it works.

AddType text/plain .py

Many thanks David.


More information about the Python-list mailing list