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

2006-10-24 Thread paulino1
I was wrong!

Now it works fine! Thank you!

I have another similar script where the print HTTP headers statement is in a
previous line... In this one it is not the case. Sorry for my inconvenience!


Paulino


Citando wesley chun [EMAIL PROTECTED]:

   

 paulino,

 mike and michael are correct. (...)

 -- wesley
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Core Python Programming, Prentice Hall, (c)2007,2001
 http://corepython.com

 wesley.j.chun :: wescpy-at-gmail.com
 python training and technical consulting
 cyberweb.consulting : silicon valley, ca
 http://cyberwebconsulting.com


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2006-10-23 Thread wesley chun
   7 print 'htmlbrbrbodypPlease enter values in the
   fields/p/body/html '
  
   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.
 
 
  import cgitb; cgitb.enable()
  That spits errors to the web page which is great for debugging cgi
  scripts.
 
  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.


paulino,

mike and michael are correct.  i know your script runs fine when the
form fields are entered.  the output is quite different tho.  as alan
and everyone has alluded to, sending output to the screen is different
than sending to a browser there is more work in order to get the
text to it.

when you display to the screen, it is a direct connect to the standard
output (not nec stdout) display, which is your monitor.  when you send
things to a browser, you have to remember that web pages flow on the
network (even on the same machine).  the protocol that is used is
called HTTP, and as the writer of software that runs on the server
side, you need to communicate to the client using that protocol
properly to the client (otherwise that defeats the purpose of even
*having* a protocol).

the headers which michael has mentioned in his above post are the
required part of the HTTP protocol that must come before any HTML is
sent (by your script).  review the recommended documents to get a good
idea of how CGI works with HTTP and HTML, and then you will be ok.

here is a Core Tip i placed on p.882 in the web programming chapter my
book (see below):

CORE TIP: HTTP headers separate from HTML
One thing that always nails CGI beginners is that when sending
results back to a CGI script, it must return the appropriate HTTP
headers first before any HTML. Furthermore, to distinguish between
these headers and the resulting HTML, several NEWLINE characters
must be inserted between both sets of data, as in line 5 of our
friends1.py example, as well as for the code in the remaining part of
the chapter.

if you happen to have access to a copy of the book, that chapter will
really help you really understand how to write a CGI script
successfully. basically, my summary is this: you will see a lot of
500/ISE errors and cgitb is your friend.  :-)

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core Python Programming, Prentice Hall, (c)2007,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2006-10-22 Thread Michael P. Reilly
On 10/21/06, Paulino [EMAIL PROTECTED] wrote:



  
  




  Mike Hansen 
Mike.Hansen at atmel.com   

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 'htmlbrbrbodypPlease 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 cgiscripts.I think you needprint 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.Actually, this is the point. The first lines of output from your CGI script, even on an error, needs to be header information to the web server and to the web browser, then a blank line, and 
then the content to be displayed (text, html, image, etc.). If you don't include the print 'Content-type: text/html\n' line that Mike suggests, then your HTML will be swallowed by the system as configuration information (and erroneous information at that).
Mike suggested some webpages to review. It might be good to pour over them to learn more about the CGI protocols. -Arcege-- There's so many different worlds,So many different suns.
And we have just one world,But we live in different ones.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2006-10-21 Thread Paulino






  Mike Hansen 
Mike.Hansen at atmel.com
   

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 'htmlbrbrbodypPlease 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" 
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.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2006-10-16 Thread Mike Hansen
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Paulino
 Sent: Sunday, October 15, 2006 10:10 AM
 To: tutor@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 'htmlbrbrbodypPlease 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@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

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2006-10-15 Thread Paulino
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 'htmlbrbrbodypPlease 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@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2006-10-15 Thread Alan Gauld
Hi Paulino,

 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 'htmlbrbrbodypPlease enter values in the
 fields/p/body/html '
 8 sys.exit(0)
 
 
 When the excption occurs, no message is shown on the browser.

Can you tell us a bit more about the set up?
What OS? What web server? 

Can you get any other python CGI scripts running correctly?

 If I run the script with IDLE, the message is printed and then the
 script exits.

The IDE environment is very different to a web server environment.

You should only treat IDLE as a first approximation when 
developing Web scripts. You can use the OS prompt for a slightly 
better approximation provided you set some environment variables 
first, but ultimately you need to test on the web server you will 
be using.

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2006-10-15 Thread Paulino




Thank you,

Yes I have other scripts working fine.

The OS is WXP and the server is the python's CGIHTTPserver (for an intranet use only)


-
Hi Paulino,

 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 'htmlbrbrbodypPlease enter values in the
 fields/p/body/html '
 8 sys.exit(0)
 
 
 When the excption occurs, no message is shown on the browser.

Can you tell us a bit more about the set up?
What OS? What web server? 

Can you get any other python CGI scripts running correctly?

 If I run the script with IDLE, the message is printed and then the
 script exits.

The IDE environment is very different to a web server environment.

You should only treat IDLE as a first approximation when 
developing Web scripts. You can use the OS prompt for a slightly 
better approximation provided you set some environment variables 
first, but ultimately you need to test on the web server you will 
be using.

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor