cgi post problem
jano
jnana4 at DELETEhotmailCAPS.com
Tue Sep 24 00:32:37 EDT 2002
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