cgi post problem
Jeff Davis
jdavis at empires.org
Tue Sep 24 05:23:17 EDT 2002
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 alignment
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
jano wrote:
> Hi,
>
> I am trying to post a form to a cgi script. The form is as follows:
>
> <form action="http://someurl.com/cgi-bin/updatexml.py" method="POST">
> <input type="text" name="/Product/Name" size="20" />
> <input type="text" name="/Product/PartNumber" size="20" />
> <input type="text" name="/Product/Inventory" size="20" />
> <input type="text" name="/Product/Cost" size="20" />
> <input type="text" name="/Product/WholesalePrice" size="20" />
> <input type="submit" value="Update Records" />
> </form>
>
> At the other end, the updatexml.py file currently just echoes back the
> form data, as follows (with some wrapper code):
>
> #!/usr/local/bin/python
>
> import sys, traceback, cgi
>
> excText = ""
>
>
> def main():
> global excText
> try:
> form = cgi.FieldStorage()
> keys = 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'
> 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
> <head>
> <title>CGI exception</title>
> <link type='text/css' rel='stylesheet' href='style.css'
> /> <script language=\"javascript\" type=\"text/js\"
> href=\"scripts/Netscape4Fix.js\"></script>
> </head>
> <body>
>
> """)
> print "<p>** ",keys," **</p>"
> print "</body></html>"
>
>
> except:
> print "Content-type: text/html\n\n"
> import time
> errtime = '--- '+ time.ctime(time.time()) +' ---\n'
> errlog = open('cgi_errlog', 'a')
> errlog.write(errtime)
> traceback.print_exc(None, errlog)
> errlog.close()
> print("""<?xml version='1.0' encoding='UTF-8'?>
> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN'
> 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
> <head>
> <title>CGI exception</title>
> <link type='text/css' rel='stylesheet' href='style.css'
> /> <script language=\"javascript\" type=\"text/js\"
> href=\"scripts/Netscape4.js\"></script>
> </head>
> <body>
> <div id=\"main\">
> """)
> print "<p class='error'>Sorry, a problem was encountered running
> the
> cgi script: </p><br />\n"
> if excText != "":
> print "<p class='citation'>", excText, "</p>"
> print "</div></body></html>"
>
>
> if __name__ == "__main__":
> main()
>
> ==================
>
> The output of the script is always an empty []. Does anybody know what
> the
> problem might be? In a previous thread, the problem was that the user
> had <input id=""...> instead of using name ="", but that is not the case
> here.
>
> Thanks for any help. I have checked usenet and the python faq and used
> google, to no avail.
>
> jano
More information about the Python-list
mailing list