Help with 500 error on cgi script

Sheila King sheila at spamcop.net
Sun Mar 18 05:29:08 EST 2001


On Sun, 18 Mar 2001 11:00:22 +0100, Steve Purcell <stephen_purcell at yahoo.com>
wrote in comp.lang.python in article
<mailman.984909623.8814.python-list at python.org>:

:You need to write out a 'Content-type' header when form_ok is true, too!
:
:It's the lack of that header that causes the 500 error. If you're pretty
:sure your content is going to be text/html, it can be good practice to write
:out the content header before any other code.

That is a good point, although I don't think that that is what the problem
was, because now I've changed the script to this, where I print the Content
header right away, and still I'm having problems. More below:


#!/usr/bin/env python


import cgi

print "Content-type: text/html\n"
print "<HTML>\n<Head>\n<Title>Result Page</Title></Head><Body>"

form = cgi.FieldStorage()
form_ok = 0
    
if form.has_key("subscriberEmail") and form.has_key("command"):
    form_ok = 1
if not form_ok:
	output = '''<H1>Error</H1>
You have not filled out all necessary information to complete this request
You <b>MUST</b> fill in your subscriber e-mail in the From: box
and you <b>MUST</b> select some action to modify your delivery options.
Please use the back button on your browser to return to the form and fill
in the required information
</body>\n</html>
'''
	print output
else:
	print "<H1>Good Result!</H1>
	print "</body>\n</html>"
"""	for k in form.keys():
    	print k, " : ", form[k]
	print "All done!"""




And I'm still getting errors. The Apache error log says, on the last run:

[Sun Mar 18 02:18:42 2001] [error] [client 4.3.200.226] Premature end of
script headers: e:/apache/cgi-bin/testform.py
[Sun Mar 18 02:18:42 2001] [error] [client 4.3.200.226]   File
"e:/apache/cgi-bin/testform.py", line 25

[Sun Mar 18 02:18:42 2001] [error] [client 4.3.200.226]     print "<H1>Good
Result!</H1>

[Sun Mar 18 02:18:42 2001] [error] [client 4.3.200.226]
^

[Sun Mar 18 02:18:42 2001] [error] [client 4.3.200.226] SyntaxError: invalid
token


But I'm at a loss to figure out what is wrong. :-(

:-Steve
:
:P.S. What's with the 'spamcop' reply address? Is that your real address or
:do unsuspecting helpful responders get their mail accounts terminated?

http://spamcop.net is a service that I subscribe to. Nothing untoward happens
to helpful responders. It is a protection for me, so that I do not have to
reveal my "real" e-mail address in the newsgroups. But, if you reply, the
replies will be delivered to me. If spammers reply, though, they will be
easily and promptly reported.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/





More information about the Python-list mailing list