Trying to write CGI script with python...

M.E.Farmer mefjr75 at hotmail.com
Fri Apr 29 16:27:56 EDT 2005


I found an excellent example that was posted by the F-bot.
Fredrik Lundh  	  May 26 2000
From: "Fredrik Lundh" <fred... at pythonware.com>
Date: 2000/05/26

richard_chamberl...@ wrote:
> I'm having great difficulties getting Python to work via CGI.

> Is there anyway I can get the traceback on to the web page so I know
what's
> happening?

the easiest way is to split your CGI module in two parts; use the
following
script as a wrapper, and place the program logic in a separate script
("my-
script.main()" in this case):

#!/usr/bin/env python

import cgi, StringIO, sys, traceback

try:
    import myscript
    myscript.main()
except:
    print "Content-Type:", "text/html"
    print
    file = StringIO.StringIO()
    traceback.print_exc(file=file)
    print "<pre>"
    print cgi.escape(file.getvalue())
    print "</pre>"

> I haven't got access to error logs so I can't look at it that way.

</F>




More information about the Python-list mailing list