cgi post problem

jano notvalid at
Tue Sep 24 13:45:03 EDT 2002

"Jeff Davis" <jdavis at> wrote in message
news:9aWj9.39314$V7.10439005 at
> Hi,
> It looks as though you have a lot of code. It might be helpful to try to
> narrow the problem further by removing a lot of the code unrelated to your
> problem, which appears to be that "keys" does not contain any items. After
> you work that out, then put the other code back in.
> My first impression is that you have some "weird" form element names
> because they contain the "/" character. That might be perfectly legal, but
> perhaps the cgi.FieldStorage class does not properly handle such element
> names, or perhaps it considers such names erroneous.
> Next, it seems that the line "keys = form.keys()" might be out of
> with the rest of the code in it's block. Perhaps it's just the way it
> looks after you copied your code into the post.
> Regards,
>         Jeff

Yes, the problem is that keys does not contain any items.  The 'weird' names
are not the problem, because i tried it also with regular 1-word names (no
slashes), with the same results.  Also, the keys=form.keys() line is
properly indented in the code -- it was just a copy/paste problem.  Here is
the code again, with the extraneous stuff stripped out:


import cgitb; cgitb.enable()
import sys, traceback, cgi

def main():
        form = cgi.FieldStorage()
        input = form.keys()

        print "Content-type: text/html\n\n"
        print("""<?xml version='1.0' encoding='UTF-8'?>
        <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN'
        <html xmlns='' xml:lang='en'>
        print "<p>",keys,"</p>"
        print "</body></html>"

if __name__ == "__main__":

And the form is:

<form action="" method="post">
     <input type="text" name="Name" size="20" />
     <input type="text" name="PartNumber" size="20" />
     <input type="text" name="Inventory" size="20" />
     <input type="text" name="Cost" size="20" />
     <input type="text" name="WholesalePrice" size="20" />
    <input type="submit" value="Update Records" />

The script, again, is currently just supposed to return the keys, which I am
expecting to be Name, PartNumber, etc., but it returns only an empty list.
Any ideas.



More information about the Python-list mailing list