Hello Word in CGI
Curtis Jensen
cjensen at bioeng.ucsd.edu
Thu Jul 6 13:05:40 EDT 2000
Bjorn Pettersen wrote:
>
> What you're seeing are the symptoms of Python having thrown an exception
> and the weblog not capturing all the information. The solution is to make
> sure Python can only throw where you can grab the exception and do
> something useful with it, like printing it to the browser... Try the
> following (but make sure you can execute it from the command line first --
> one possible error is a SyntaxError, which this scheme will not save you
> from...)
>
> -- bjorn
>
> #!/usr/bin/env python
> print """Content-type: text/html
>
> """
>
> def main():
> from time import *
>
> print "<HTML>"
> print "<Head>"
> print "<Title>Hello World</Title>"
> print "</Head>"
> print "<Body>"
> print "<H1>Hello World !</H1>"
> print "<hr>"
> print "<P>This is San Diego.<br>Localtime is", ctime( time() ) + ".<P>"
>
> print "</Body>"
> print "</HTML>"
>
> import traceback
>
> def execute(fn):
> # make sure any errors are legible, and directed to the user.
> try:
> sys.stderr = sys.stdout
> fn()
> except:
> print '<h1>Something went wrong!!!</h1>'
> print 'Please send the transcript below to webmaster at your.web<p>'
> print '\n\n<pre>'
> traceback.print_exc()
>
> execute(main)
>
I tried this. I got the same errors in the log and in the browser. I
took out the print line since it caused a discussion. Any more
suggestions? Thanks.
--
Curtis Jensen
cjensen at bioeng.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451
More information about the Python-list
mailing list