[Tutor] Exception and sys.exit() in a cgi script
Paulino
paulino1 at sapo.pt
Sun Oct 22 03:35:13 CEST 2006
> *Mike Hansen*
> Mike.Hansen at atmel.com
> <mailto:tutor%40python.org?Subject=%5BTutor%5D%20Exception%20and%20sys.exit%28%29%20in%20a%20cgi%20script&In-Reply-To=>
>
> /Mon Oct 16 18:43:29 CEST 2006/
> >/ 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>
> />/ 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"
> http://docs.python.org/lib/cgi-intro.html
>
> http://docs.python.org/lib/node560.html
>
> Mike
Thats not the point (sorry).
when all the values are provided in the form (no excetion is raised) it
runs as expected!
The point is when one of the values "ano", "conta" is missing in the
form, I want the error message to be shown on the browser, and the
script to stop running.
When there is an exception, the script actually stops running, but no
message is sent to the browser.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061022/4963c3fb/attachment.html
More information about the Tutor
mailing list