Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ubuntu 12.10 Server in a virtualbox VM.

I have installed mod_python using apt-get,enabled it using a2enmod, and rebooted apache2. I have also edited \etc\apache2\sites-available\defaults as below. My script resides in /var/www/py/ and is called via a jQquery.ajax post function. This script is triggering, but returns itself - in plain text. It should be returning json, indicating that I have missed some obvious setup step.

Uncommenting the testhandler line, below, results in the script returning mod_python.testhandler output - essential the output, but for python.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        <Directory /var/www/>
                Options Indexes FollowSymLinks Indexes MultiViews
                AllowOverride None
                Order allow,deny
                allow from all

         ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride All
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all

        <Directory /var/www/py>
                Options Indexes FollowSymlinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                AddHandler mod_python .py
                #PythonHandler mod_python.testhandler
                PythonDebug On
share|improve this question
I can't understand what is the problem here. What are you expecting?, it is a response header problem?, did you encode your response in json inside your python script?. Please add more detail. BTW, mod_python is deprecated you should try to use wsgi. – Javier Rivera Jan 28 '13 at 8:17

As a non-answer to your question: mod_python is no longer the recommended way of deploying python applications. Turning your application into a proper wsgi app and using mod_wsgi is the state of the art.

Now for an actual answer: You'll need to set up a handler. mod_python doesn't just run random scripts, but you need to specify which module contains the handler, this is what AddHandler does.

For more info, see the mod_python tutorial.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.