<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<blockquote cite="midmailman.1234.1160934931.11738.tutor@python.org"
type="cite">
<pre wrap=""><b>Mike Hansen</b>
<a
href="mailto:tutor%40python.org?Subject=%5BTutor%5D%20Exception%20and%20sys.exit%28%29%20in%20a%20cgi%20script&In-Reply-To="
title="[Tutor] Exception and sys.exit() in a cgi script">Mike.Hansen at atmel.com
</a>
<i>Mon Oct 16 18:43:29 CEST 2006</i>
><i> This is a peace of a CGI script i have.
</i>><i>
</i>><i> 1 import cgi
</i>><i> 2 form=cgi.FieldStorage()
</i>><i> 3 try :
</i>><i> 4 ano=form["ano"].value
</i>><i> 5 conta=form["conta"].value
</i>><i> 6 except KeyError :
</i>><i> 7 print '<html><br><br><body><p>Please enter values in the
</i>><i> fields</p></body></html> '
</i>><i> 8 sys.exit(0)
</i>><i>
</i>><i>
</i>><i> When the excption occurs, no message is shown on the browser.
</i>><i>
</i>><i> If I run the script with IDLE, the message is printed and then the
</i>><i> script exits.
</i>><i>
</i>><i> What's wrong here?
</i>><i>
</i>><i>
</i>><i>
</i>><i> _______________________________________________
</i>><i> Tutor maillist - <a
href="http://mail.python.org/mailman/listinfo/tutor">Tutor at python.org</a>
</i>><i> <a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a>
</i>><i> </i> </pre>
<pre wrap="">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"
<a href="http://docs.python.org/lib/cgi-intro.html">http://docs.python.org/lib/cgi-intro.html</a>
<a href="http://docs.python.org/lib/node560.html">http://docs.python.org/lib/node560.html</a>
Mike</pre>
</blockquote>
<br>
Thats not the point (sorry).<br>
<br>
when all the values are provided in the form (no excetion is raised) it
runs as expected!<br>
<br>
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.<br>
<br>
When there is an exception, the script actually stops running, but no
message is sent to the browser.<br>
</body>
</html>