You wrote:

The error message you get "Premature end of script headers" means
that the HTTP header generated by your CGI is not correct.  You need
at least to tell the webserver what content type your CGI generates
before sending any further data.  For example in a sh script:

#!/bin/sh

echo "Content-Type: text/html"
echo ""
echo "I'm sorry Dave, I'm afraid I can't do that."
Yes - in my experience, this is prolly the cause.  It usually happens
when you try to print before printing this header above.

When I write CGI's I usually break my code into sections.

* Grab any field data from the request, making sure I don't print anything. (I usually will store any errors I get into a string, for later printing)

 * Process the field data, and store any resulting errors into a string.

 * print out the HTML response - Here is where you have to print the
    "Content-Type" header...

Very often when debugging CGI's I work from the Python shell, and by breaking it up like this, makes it easy to debug. Run the cgi from the python shell, and
see what you get back,   should be HTML.

You wouldn't be able to process the forms data of course, but we are just making sure the printing part is working. Any errors you get before that part of the code has to be put into a error_result string, which is usually the HTML one gets back
after submitting the form.

Sometimes when I have to "fake it", I make up a special test module and import it if running from the shell - it would then put "fake" form data, and return a "cgi" dictionary just like what you would get from the initial request.
Hope this helps - I don't know much about chrooted cgi's, because now I use
Twisted Python for my back end web processing, with my own security systems.

John

Reply via email to