Mod_python not getting GET variables

492 views Asked by At

I have standard 13.10 Ubuntu. Running Apache 2 and mod_python. Both installed using apt-get. I'm trying to pass a GET variable from the client to the server, execute python script and then return a result.

Here is my ApacheConfig (Default plus code below):

ScriptAlias /tm/ "/home/tm/"

<Directory /home/tm/ >
        Require all granted
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
        AddHandler mod_python .py
        PythonHandler mod_python.publisher
        PythonDebug On
</Directory>

Python Code: test.py

import csv

def index():
    form = cgi.FieldStorage()
    return form

I tried http://myWebsite.com/tm/test.py?testVariable=This

returns: FieldStorage(None, None, []) - Meaning the GET variables are not being passed over.

1

There are 1 answers

0
bauman.space On

As others have said in comment, you should try to use anything other than mod_python. Flask is an excellent python microframerwork http://flask.pocoo.org/

Assuming you are for some reason locked to mod_python: You need to read the input variable, you are instead creating a new blank instance and returning that.

def index():
  form = cgi.FieldStorage() #this is creating a new/blank instance
  return form

you want to read the global copy in the "req" variable:

def index():
    return req.form

Again, if you have a choice, please do everything you can to avoid using mod_python. It was good in its day, but shouldn't be your go to python web framework.