This issue is most likely embarrassingly simple.

I am attempting to give python a spin. I figured a great way to start doing that might be to produce a simple cgi script to process some form data and perform some miracle. My python script is performed correctly by apache using mod_python, and can print whatever I would like it to print.

My only issue is that cgi.FieldStorage() is definitely empty. I have attempted using both Publish and obtain. Each trial I complete both form fields.

<form action="" method="POST" name="ARGH">
<input name="TaskName" type="text" />
<input name="TaskNumber" type="text" />
<input type="submit" />

Basically alter the form to suggest to some perl script it reviews the shape data correctly. The python page always provides me with exactly the same result: quantity of secrets:


    import cgi

    def index(req):

            pageContent = """<html><head><title>A page from"""
            pageContent += """Python</title></head><body>"""
            form = cgi.FieldStorage()
            keys = form.keys()
            pageContent += "<br />number of keys: "+str(len(keys))
            for key in keys:
                    pageContent += fieldStorage[ key ].value
            pageContent += """</body></html>"""
            return pageContent

I am using Python 2.5.2 and Apache/2.2.3. This really is what's during my apache conf file (and my script is within /var/www/python):

   <Directory /var/www/python/>
      Options FollowSymLinks +ExecCGI
      Order allow,deny
      allow from all
      AddHandler mod_python .py
      PythonHandler mod_python.publisher

Your condition is the fact that you are mixing two different approaches: CGI and mod_python. You declare your script like a mod_python writer, and that's why its index method will get known as -- and that also causes it to be a module, not really a script.

Should you be using CGI, you'd take away the mod_python directives out of your Apache configuration, just leave the ExecCGI, and only relabel the script to achieve the .cgi extension or set the handler for that .py extension to become CGI, too. Your script could be performed like a script, meaning the index function you defined inside your script would not be performed unless of course you known as it in the toplevel from the script.

When I recall -- but it is been a very long time since i have bothered with mod_python -- if you wish to use mod_python rather, you ought to be using mod_python.util.FieldStorage rather than cgi.FieldStorage to gain access to the Publish data.

All nevertheless, a much better option for bare-bones web stuff is WSGI, for instance through mod_wsgi. In most cases superior to bare-bones web stuff is applying an internet framework, like Django, TurboGears, Pylons, or one of the numerous others for auction on, for instance, the web frameworks page on