Cgi.FieldStorage is always empty - never returns POSTed form Data

This problem is probably awkwardly simple.

I'm trying to give python a spin. I thought that a good way to start this would be to create a simple cgi script to process data in a certain form and create some magic. My python script runs apache correctly with mod_python and prints everything I want it to print.

My only problem is that cgi.FieldStorage () is always empty . I tried using both POST and GET. In each test, I fill out both form fields.

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

If I change the form to point to a perl script, it correctly reports the form data. The python page always gives me the same result: number of keys: 0

#!/usr/bin/python

    import cgi

    def index(req):

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

Python 2.5.2 Apache/2.2.3. , apache conf ( script /var/www/python ):

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

, : CGI mod_python. script mod_python, index - , script.

CGI, mod_python Apache, ExecCGI script, .cgi .py, CGI, . script script, , index, script, , script.

, mod_python - mod_python , mod_python.util.FieldStorage cgi.FieldStorage POST.

, , - - WSGI, , mod_wsgi. , , , - , -, Django, TurboGears, Pylons , , , - wiki.python.org

+6

Source: https://habr.com/ru/post/1744339/


All Articles