Hello Word in CGI

Bjorn Pettersen bjorn at roguewave.com
Wed Jul 5 21:54:31 EDT 2000


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)



Curtis Jensen wrote:

> We get this error in our server log:
> Wed Jul  5 16:12:52 2000] [error] [client 132.239.236.47] Premature end
> of script headers:
> /usr/local/httpd/cgi-bin/test_jmsun/cont_forms/helloworld.py
>
> The browser gives us this error:
> Internal Server Error
>
> The server encountered an internal error or misconfiguration and was
> unable to complete your request.
>
> Please contact the server administrator, webmaster at bioeng.ucsd.edu and
> inform them of the time the error occurred, and
> anything you might have done that may have caused the error.
>
> More information about this error may be available in the server error
> log.
>
> Apache/1.3.6 Server at cmrg.ucsd.edu Port 80
>
> Using this script from:
> http://www.ping.be/sabine-appelmans/home/python/index.html
>
> #!/usr/local/Python/bin/python
> #
> # helloworld.py
> #
>
> from time import *
>
> print "Content-type: text/html"
> print
>
> 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>"
>
> Any ideas why?
>
> --
> Curtis Jensen
> cjensen at bioeng.ucsd.edu
> http://www-bioeng.ucsd.edu/~cjensen/
> FAX (425) 740-1451
> --
> http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list