[Tutor] CGI error

Martin Walsh mwalsh at groktech.org
Sat Jul 14 17:44:01 CEST 2007


Hi Darren,

Darren Williams wrote:
>  Hi all Smile
> 
> I have a Windows hosting account with lunarpages.com and am having a bit
> of trouble with CGI. I have enabled both CGI and Python in the control
> panel and made sure the permissions for all my CGI scripts are set to
> both readable and executable for all users but I keep getting the same
> 'The specified CGI application misbehaved by not returning a complete
> set of HTTP headers' error.

Have you tried to run the script from the command line? If the code
provided below is accurate and has not been changed by your mail client,
then it will raise an IndentationError, and the script will exit before
printing the Content-type header.

> The script that i'm trying to execute (example_7.1.py) -
<snip/>
>   32.     # Define function display data.
>   33.     def display_data(name, age):

Here is an improper indent ...

>   34.     print "<HTML>\n"
>   35.     print "<HEAD>\n"
>   36.     print "\t<TITLE>Info Form</TITLE>\n"
>   37.     print "</HEAD>\n"
>   38.     print "<BODY BGCOLOR = white>\n"
>   39.     print name, ", you are", age, "years old."
>   40.     print "</BODY>\n"
>   41.     print "</HTML>\n"
>   42.
>   43.     # Define main function.
>   44.     def main():

... and here ...

>   45.     form = cgi.FieldStorage()
>   46.     if (form.has_key("action") and form.has_key("name") \
>   47.     and form.has_key("age")):
>   48.              if (form["action"].value == "display"):
>   49.                 display_data(form["name"].value, form["age"].value)
>   50.     else:
>   51.              generate_form()
>   52.
>   53.     # Call main function.
>   54.     main()

... and here ...

HTH,
Marty


More information about the Tutor mailing list