[Tutor] cgi scripts
Jim Morcombe
jmorcombe at westnet.com.au
Sat Nov 8 09:10:29 CET 2008
Bt "Crash", I mean the browser displays:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
The code I sent before had a silly mistake in it. Here is a better
example of the things I am trying and failing at.
I can print a single key. I can iterate over the keys, just printing
out "hello" for each iteration.
But I can't figure out how to iterate over all the keys printing out
somethinf sensible.
#!C:\python25\python.exe
import cgi, sys
# import cgitb; cgitb.enable()
#Send errors to browser
sys.stderr = sys.stdout
#Parse data from form
data = cgi.FieldStorage()
#Send response to browser
print "Content-type: text/html\n"
print "<title>CGI Form Response</title>\n"
print "<h2>This is the data passed to the cgi script</h2><P>"
# This next bit works and I can see a list of keys displayed in the browser
print "Version 4: data.keys()\n"
print "<br>"
print data.keys()
# This next bit also works and I can see the value of the variable
"JQuiz_q01_score"
print "<P>-----------------"
print "<B>JQuiz_q01_score = ", data["JQuiz_q01_score"].value
# However, whenever I try to iterate over all the keys, I get the
"Internal Server error"
print "<P>-----------------"
for k in data.keys():
print "<BR>"data[k].key
# I have also tried data[k]
# data.key[k]
# data[k].value
# and many other random combinations.
More information about the Tutor
mailing list