Very useful message -- Hah!

Nathan Clegg nathan at islanddata.com
Mon Dec 6 12:06:23 EST 1999


On 04-Dec-99 Dan Grassi wrote:
> It seems that by design python, by design, is not to be used as a cgi
> scripting language -- otherwise why would it produce this very
> meaningful
> message at the slightest syntax error:
> 
> 
> Internal Server Error


This is the web server's error.  You will have to check the web server cgi
error logs to find python's (much more useful) error message.  If nothing
else, this offers you a little bit of security.  You wouldn't want hackers
knowing exactly what kind of errors they can produce or give away telling
tracebacks.

However, ideally you will never have these errors in a production
situation, so this is what I do when under development:

Wrap the whole thing (perhaps a main function) in a try block.  catch any
uncaught errors outside and print it out nicely.  Here's a scrap of code I
use:



def print_exception():
    from traceback import print_exc
    tempstd = sys.stderr
    sys.stderr = sys.stdout
    print_exc()
    sys.stderr = tempstd

....

    try:        
        main()
    except:
        print 'Content-Type: text/plain'
        print
        print 'An unexpected error has occurred.  Please report'
        print 'the following information to the webmaster at'
        print 'webmaster at website.com'
        print
        print
        print_exception()


----------------------------------
Nathan Clegg
 nathan at islanddata.com






More information about the Python-list mailing list