Re: [Tutor] cgi scripts

2008-11-10 Thread Kent Johnson
On Mon, Nov 10, 2008 at 7:00 AM, Jim Morcombe [EMAIL PROTECTED] wrote:
 I have been using
   import cgitb; cgitb.enable()

 It seems to re-direct some of the errors to the browser, but obviously not
 all.

Right, if the script fails before that line runs, of course it will
have no effect.

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


Re: [Tutor] cgi scripts

2008-11-10 Thread Jim Morcombe
Actually, that's good to know.  I was thinking it was going to be pretty 
hard to debug if I couldn't tell the difference between HTML errors and 
Python errors.

I have been using
   import cgitb; cgitb.enable()

It seems to re-direct some of the errors to the browser, but obviously 
not all.


Jim



Don Jennings wrote:

Hi, Jim. Actually, improper HTML would cause a problem with the
browser and what it may or may not display. An Internal Server Error
does indicate that you had a problem with your code. I suggest
referring back to Alan's post again.

Take care,
Don


  



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


Re: [Tutor] cgi scripts

2008-11-09 Thread Tim Johnson
On Saturday 08 November 2008, Kent Johnson wrote:
 On Sat, Nov 8, 2008 at 3:38 AM, Jim Morcombe [EMAIL PROTECTED] 
wrote:
  I think the problem wasn't in getting the keys and values, but I might
  have been producing illegal HTML code before.
  I think I'd better brush up on my HTML skills.

 Poorly formed HTML won't give an internal server error. That is due to
 something more serious such as a syntax error in your program.
   I always configure cgi scripts so that I can also run them from the command
   line. That can be an effective way to catch errors otherwise obfuscated
   by the browser. Although I don't use windows any longer, I recall that
   pythonwin was a nice IDE to use and it probably has a syntax checker.
tim



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


Re: [Tutor] cgi scripts

2008-11-08 Thread Jim Morcombe

Bt Crash, I mean the browser displays:


 Internal Server Error

The server encountered an internal error or misconfiguration and was 
unable to complete your request.



The code I sent before had a silly mistake in it.  Here is a better 
example of the things I am trying and failing at.
I can print a single key.  I can iterate over the keys, just printing 
out hello for each iteration.
But I can't figure out how to iterate over all the keys printing out 
somethinf sensible.


#!C:\python25\python.exe

import cgi, sys
# import cgitb; cgitb.enable()

#Send errors to browser
sys.stderr = sys.stdout

#Parse data from form
data = cgi.FieldStorage()

#Send response to browser
print Content-type: text/html\n
print titleCGI Form Response/title\n
print h2This is the data passed to the cgi script/h2P

# This next bit works and I can see a list of keys displayed in the browser
print Version 4: data.keys()\n
print br
print data.keys()

# This next bit also works and I can see the value of the variable 
JQuiz_q01_score

print P-
print BJQuiz_q01_score = , data[JQuiz_q01_score].value

# However, whenever I try to iterate over all the keys, I get the 
Internal Server error

print P-
for k in data.keys():
   print BRdata[k].key

#  I have also tried data[k]
#data.key[k]
#data[k].value
#  and many other random combinations.


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


Re: [Tutor] cgi scripts

2008-11-08 Thread Alan Gauld


Jim Morcombe [EMAIL PROTECTED] wrote

The code I sent before had a silly mistake in it.  Here is a better 
example of the things I am trying and failing at.


Look at what you are doing in the two examples

# This next bit also works and I can see the value of the variable 
print BJQuiz_q01_score = , data[JQuiz_q01_score].value


# However, whenever I try to iterate over all the keys, I get the 
print BRdata[k].key


Can you see what you are doing differently whwen accessing
the data?

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


Re: [Tutor] cgi scripts

2008-11-08 Thread Jim Morcombe

Thanks guys,

This works :)

field_list = 'ul\n'
for field in data.keys():
   field_list = field_list + 'li%s : %s/li\n' % (field, 
data[field].value)

field_list = field_list + '/ul\n'
print field_list

I think the problem wasn't in getting the keys and values, but I might 
have been producing illegal HTML code before.

I think I'd better brush up on my HTML skills.

Jim





Alan Gauld wrote:


Jim Morcombe [EMAIL PROTECTED] wrote

The code I sent before had a silly mistake in it.  Here is a better 
example of the things I am trying and failing at.


Look at what you are doing in the two examples

# This next bit also works and I can see the value of the variable 
print BJQuiz_q01_score = , data[JQuiz_q01_score].value


# However, whenever I try to iterate over all the keys, I get the 
print BRdata[k].key


Can you see what you are doing differently whwen accessing
the data?

HTH,





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


Re: [Tutor] cgi scripts

2008-11-08 Thread Kent Johnson
On Sat, Nov 8, 2008 at 3:38 AM, Jim Morcombe [EMAIL PROTECTED] wrote:

 I think the problem wasn't in getting the keys and values, but I might have
 been producing illegal HTML code before.
 I think I'd better brush up on my HTML skills.

Poorly formed HTML won't give an internal server error. That is due to
something more serious such as a syntax error in your program.

With bad HTML you will see *something* in the browser, even if only a
blank page, and you can view source to see the actual code.

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


Re: [Tutor] cgi scripts

2008-11-08 Thread Don Jennings
(Oops! Forgot to include tutor in recipient.)

On 11/8/08, Don Jennings [EMAIL PROTECTED] wrote:
 Hi, Jim. Actually, improper HTML would cause a problem with the
 browser and what it may or may not display. An Internal Server Error
 does indicate that you had a problem with your code. I suggest
 referring back to Alan's post again.

 Take care,
 Don

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


Re: [Tutor] cgi scripts

2008-11-07 Thread Steve Willoughby

Jim Morcombe wrote:
I want to print a list of the keys and their values passed to a cgi 
script by an HTML form.

I have tried this, but just seems to crash.


When you say crash, what do you mean, exactly?


Any ideas?



print Content-type: text/html\n
print titleCGI Form Response/title\n
print h2This is the data passed to the cgi script/h2P


It wouldn't hurt to output fully-formed HTML here.


print for k in data.keys():


I think you'll find the source of your problem right about here.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor