[Tutor] Exception and sys.exit() in a cgi script

Mike Hansen Mike.Hansen at atmel.com
Mon Oct 16 18:43:29 CEST 2006


 

> -----Original Message-----
> From: tutor-bounces at python.org 
> [mailto:tutor-bounces at python.org] On Behalf Of Paulino
> Sent: Sunday, October 15, 2006 10:10 AM
> To: tutor at python.org
> Subject: [Tutor] Exception and sys.exit() in a cgi script
> 
> This is a peace of a CGI script i have.
> 
> 1 import cgi
> 2 form=cgi.FieldStorage()
> 3 try :
> 4     ano=form["ano"].value
> 5     conta=form["conta"].value
> 6 except KeyError :
> 7     print '<html><br><br><body><p>Please enter values in the
> fields</p></body></html> '
> 8     sys.exit(0)
> 
> 
> When the excption occurs, no message is shown on the browser.
> 
> If I run the script with IDLE, the message is printed and then the
> script exits.
> 
> What's wrong here?
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

I'm catching up on the weekend's tutor messages.

import cgitb; cgitb.enable()
That spits errors to the web page which is great for debugging cgi
scripts.

I think you need
print "Content-Type: text/html\n\n"
Before your print html statement.

http://docs.python.org/lib/cgi-intro.html

http://docs.python.org/lib/node560.html

Mike



More information about the Tutor mailing list