cgi help

Kevin O'Gorman kevin
Mon May 17 11:30:13 PDT 2004


It helps if you can hold off setting the reply headers until you
know whether you have an error or not.  If you can, then you can
force the reply to be plain text, which makes debugging a bit
easier, in general.  It can be hard to do the right thing with
an error message when you've already output 10,000 bytes of HTML
and you don't know what part of the page you're on.

In python, which I've used a lot for that purpose, my pattern on
error goes something like this:

import cgi

def cgiput(s):
    ofile.write("%s\r\n" % s)

try:
	<stuff>
except Exception, e:
	if <debugging>:
		cgiput("content-type: text/plain")
	cgiput("Status: 500 Internal Server Error")
	cgiput("")
	cgiput("Cannot parse the PATH_INFO: %s" % pi)
	sys.exit(0)

If I'm debugging, this comes out as text, and I usually write
a whole bunch of other stuff too.

You can play with this in various ways, of course.  YMMV.

++ kevin


On Sat, Apr 20, 2002 at 09:46:23PM +0000, Richard R. Sivernell wrote:
> List
> 
>    I am now able to get access to my cgi program, but the error msgs that 
> are returned are at best pathetic. Does any one know how to set return 
> messages to give detailed info. tring to debug cgi program.
> 
> cheers

-- 
Kevin O'Gorman  (805) 650-6274  mailto:kevin at kosmanor.com
Permanent e-mail forwarder:  mailto:Kevin.O'Gorman.64 at Alum.Dartmouth.org
At school: mailto:kogorman at cs.ucsb.edu
Web: http://www.cs.ucsb.edu/~kogorman/index.html
Web: http://kosmanor.com/~kevin/index.html

"Life is short; eat dessert first!"



More information about the Linux-users mailing list