Re: [Tutor] cgi help

2010-10-06 Thread delegbede
Got it fixed.
Thanks y'all.
Regards,
--Original Message--
From: Dave Angel
To: Dipo Elegbede
Cc: tutor
Subject: Re: [Tutor] cgi help
Sent: Oct 6, 2010 12:30



On 2:59 PM, Dipo Elegbede wrote:
> here is the code:
>
> http://pastebin.com/K2Fxq6ac
>
> kindly help me figure out my mistake.
>
> It is supposed to return a table of environmental variables but it returns
> only the header and a blank page.
>
> thanks
>
Care to define "return" ?

How are you running this code?  How are you trapping and displaying the 
exception it gets when run?  Can you show us the traceback?  Are you 
looking at the output in a web browser?  Which one?  And are you doing a 
view-Source, or whatever your browser offers?

A CGI program is intended to run on a web server, and debugging it can 
be very difficult.  Are you sure you want this as a beginner project?

If so, then I'd start by saying you should run it locally, till you get 
rid of all the errors you'll see that way.

By inspection, I can see that you should get more than the header, you 
should also get the  element, then it'll crash on the bogus 
assignment of the uninitialized variable rowNumber.

When I run it locally, I get:

Content-type: text/html



http://www.w3.org/1999/xhtml";>
Environmental Variables



Traceback (most recent call last):
   File "M:\cgitest.py", line 27, in 
 rowNumber += 1
NameError: name 'rowNumber' is not defined


You don't initialize the global variable rowNumber to anything, but just 
increment it.

You do initialize a local variable in your function with the same name, 
but nothing is ever done with that, and of course it goes away when the 
function ends.  Same with the backgroundColor local.

To fix this problem you'll need to initialize rowNumber before the for 
statement.

DaveA



Sent from my BlackBerry wireless device from MTN
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cgi help

2010-10-06 Thread Dave Angel



On 2:59 PM, Dipo Elegbede wrote:

here is the code:

http://pastebin.com/K2Fxq6ac

kindly help me figure out my mistake.

It is supposed to return a table of environmental variables but it returns
only the header and a blank page.

thanks


Care to define "return" ?

How are you running this code?  How are you trapping and displaying the 
exception it gets when run?  Can you show us the traceback?  Are you 
looking at the output in a web browser?  Which one?  And are you doing a 
view-Source, or whatever your browser offers?


A CGI program is intended to run on a web server, and debugging it can 
be very difficult.  Are you sure you want this as a beginner project?


If so, then I'd start by saying you should run it locally, till you get 
rid of all the errors you'll see that way.


By inspection, I can see that you should get more than the header, you 
should also get the  element, then it'll crash on the bogus 
assignment of the uninitialized variable rowNumber.


When I run it locally, I get:

Content-type: text/html



http://www.w3.org/1999/xhtml";>
Environmental Variables



Traceback (most recent call last):
  File "M:\cgitest.py", line 27, in 
rowNumber += 1
NameError: name 'rowNumber' is not defined


You don't initialize the global variable rowNumber to anything, but just 
increment it.


You do initialize a local variable in your function with the same name, 
but nothing is ever done with that, and of course it goes away when the 
function ends.  Same with the backgroundColor local.


To fix this problem you'll need to initialize rowNumber before the for 
statement.


DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGI HELP

2010-10-06 Thread delegbede
Yes, so I did a pastebin and resent to the group.
Thanks.
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: Joel Goldstick 
Sender: tutor-bounces+delegbede=dudupay@python.org
Date: Wed, 6 Oct 2010 05:54:03 
To: tutor
Subject: Re: [Tutor] CGI HELP

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGI HELP

2010-10-06 Thread Joel Goldstick
On Wed, Oct 6, 2010 at 5:25 AM, Dipo Elegbede  wrote:

> Hi all,
>
> I wrote this code as an example from a book:
>
> #!c:\Python26\python.exe
> # Program displaying CGI environment variables.
>
> import os
> import cgi
>
> def printHeader(title):
> print """Content-type: text/html
>
> 
>  "-//W3C//DTD XHTML 1.0 Strict//EN"
> "DTD/xhtml1-strict.dtd">
> http://www.w3.org/1999/xhtml";>
> %s
>
> """ % title
>
> rowNumber = 0
> backgroundColour = "white"
>
> printHeader("Environmental Variables")
> print ""
>
> # print table of cgi variables and values
> for item in os.environ.keys():
> rowNumber += 1
>
> if rowNumber % 2 == 0: # even row numbers are white
> backgroundColour = "white"
> else: # odd row numbers are grey
> backgroundColour = "lightgrey"
>
> print """
> %s%s""" %(backgroundColour,
> cgi.escape(item), cgi.escape(os.environ[item]))
> print ""
>
> It was supposed to return a list of environmental variables in a given
> order.
> Sadly only the header displayed.
> I have looked through over and over, please what am i doing wrong.
> This is from Deitel How to program python, Chapter 6.
>
> thanks and best regards.
> --
>
did you lose the indentation in copying code to email?

-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] cgi help

2010-10-06 Thread Dipo Elegbede
here is the code:

http://pastebin.com/K2Fxq6ac

kindly help me figure out my mistake.

It is supposed to return a table of environmental variables but it returns
only the header and a blank page.

thanks

-- 
Elegbede Muhammed Oladipupo
OCA
+2348077682428
+2347042171716
www.dudupay.com
Mobile Banking Solutions | Transaction Processing | Enterprise Application
Development
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] CGI HELP

2010-10-06 Thread Dipo Elegbede
Hi all,

I wrote this code as an example from a book:

#!c:\Python26\python.exe
# Program displaying CGI environment variables.

import os
import cgi

def printHeader(title):
print """Content-type: text/html



http://www.w3.org/1999/xhtml";>
%s

""" % title

rowNumber = 0
backgroundColour = "white"

printHeader("Environmental Variables")
print ""

# print table of cgi variables and values
for item in os.environ.keys():
rowNumber += 1

if rowNumber % 2 == 0: # even row numbers are white
backgroundColour = "white"
else: # odd row numbers are grey
backgroundColour = "lightgrey"

print """
%s%s""" %(backgroundColour,
cgi.escape(item), cgi.escape(os.environ[item]))
print ""

It was supposed to return a list of environmental variables in a given
order.
Sadly only the header displayed.
I have looked through over and over, please what am i doing wrong.
This is from Deitel How to program python, Chapter 6.

thanks and best regards.
-- 
Elegbede Muhammed Oladipupo
OCA
+2348077682428
+2347042171716
www.dudupay.com
Mobile Banking Solutions | Transaction Processing | Enterprise Application
Development
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGI help

2005-01-18 Thread Kent Johnson
Your CGI will be run fresh each time the user submits the form. If you want data to persist between 
submits you have to either
- save the data to a persistent store - a file or database
- use a different way to handle the form - I'm not sure of all the options but I think mod_python 
and FastCGI both keep the CGI process running - or use a server like CherryPy or TwistedMatrix.

Kent
[EMAIL PROTECTED] wrote:
Im trying to make a game where in a dictionary is a list of questions and 
answers. If i try to output 6 at a time to a cgi script and submit will my 
script be reset so my delete function of not getting the same question again 
not work?

if this doesnt make sense ill repost
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] CGI help

2005-01-18 Thread rowan
Im trying to make a game where in a dictionary is a list of questions and 
answers. If i try to output 6 at a time to a cgi script and submit will my 
script be reset so my delete function of not getting the same question again 
not work?

if this doesnt make sense ill repost
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGI help

2005-01-04 Thread Rich Krauter
David Holland wrote:
Rich,
That worked although I had to set the address to :-
http://127.0.0.1:8000/friends1.html
Thanks.
Good catch, sorry about that. I noticed you had spaces in the "how many" 
field in your form. Did your cgi still work? If not, I guess you figured 
that out by now too.

Interestingly, I had trouble getting the server/cgi to work with python 
2.4/Windows XP.

If I started the server with python 2.4 and put 2.4 in the cgi's #! 
line, the cgi didn't work.

If I used 2.3 to start the server, and put 2.3 or 2.4 in the cgi's #! 
line, the cgi worked.

I tried the same combinations on linux, and they all worked fine.
Anyone else seen this problem with python 2.4 on windows xp? I looked 
quickly at diffs of the relevant codes between 2.3 and 2.4, and I did a 
quick bug search on sourceforge, but didn't turn up anything yet.

Of course it may not be a bug; it may be a problem with my setup. The 
files I used are posted below, in case anyone wants to try to reproduce 
the result I saw.

Thanks.
Rich

<>
import CGIHTTPServer
import BaseHTTPServer
def run(server_class=BaseHTTPServer.HTTPServer,
handler_class=CGIHTTPServer.CGIHTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
run()
<>
<>
#!C:/Python24/python.exe
print "Content-Type: text/html"
print
import cgi,cgitb
cgitb.enable()
reshtml = '''


CGI Demo


Friends list for:%s
Your name is: %s
You have %s friends.

'''
form = cgi.FieldStorage()
who = form.getfirst('person')
howmany = form.getfirst('howmany')
print reshtml % (who, who, howmany)
<>

<>



CGI Demo



Friends list for New User

Enter your name
How many friends do you have?
0
10
25
50
100>




<>

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


[Tutor] CGI help

2005-01-04 Thread David Holland
Rich,

That worked although I had to set the address to :-
http://127.0.0.1:8000/friends1.html
Thanks.





___ 
ALL-NEW Yahoo! Messenger - all new features - even more fun! 
http://uk.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGI help

2005-01-03 Thread Rich Krauter
David Holland wrote:
I have written my first cgi script :-
The .html code is :-

Friends CGI Demo (Static Screen)

Friends list for:New User

Enter your name>

How many friends do you have ?
0
10
25
50
100

The python code is :-
#!/usr/bin/env python
import cgi
reshtml = '''Content-Type: text/html\n

Friends CGI Demo (dynamic screen)

Friends list for: %s
Your name is: %s
You have %s friends.
'''
form = cgi.FieldStorage()
who = form['person'].value
howmany = form['howmany'].value
print reshtml % (who, who, howmany)
Now when I open the page using konqueror and click on
submit. Instead of the code running, it justs opens
the .py program in a different window.
Any ideas ? 



Hi David,
You can use a small python script to provide a cgi web server for testing:

import BaseHTTPServer
import CGIHTTPServer
def run(server_class=BaseHTTPServer.HTTPServer,
handler_class=CGIHTTPServer.CGIHTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
run()

Put this in a file called, say, server.py. In the same directory as 
server.py, put a directory called cgi-bin. Put your python cgi scripts 
in cgi-bin. Modify the action tag in your html form to point to 
/cgi-bin/friends1.py. Click on the server.py icon, or run it from the 
command line.

Finally, point your browser to http://127.0.0.1:8000/cgi-bin/friends1.py.
You'll proably want to use apache or some other server if you want to do 
more than just test or demo cgi scripts locally, but this can be a 
useful alternative for testing simple cgi programs without installing 
additional software on your machine.

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


Re: [Tutor] CGI help

2005-01-03 Thread Kent Johnson
It sounds like maybe you are opening the HTML directly from the filesystem? You have to install the 
HTML and CGI into a web server and access them through the server. The details for this will depend 
on the web server.

Kent
David Holland wrote:
I have written my first cgi script :-
The .html code is :-

Friends CGI Demo (Static Screen)

Friends list for:New User

Enter your name>

How many friends do you have ?
0
10
25
50
100

The python code is :-
#!/usr/bin/env python
import cgi
reshtml = '''Content-Type: text/html\n

Friends CGI Demo (dynamic screen)

Friends list for: %s
Your name is: %s
You have %s friends.
'''
form = cgi.FieldStorage()
who = form['person'].value
howmany = form['howmany'].value
print reshtml % (who, who, howmany)
Now when I open the page using konqueror and click on
submit. Instead of the code running, it justs opens
the .py program in a different window.
Any ideas ? 

	
	
		
___ 
ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

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


[Tutor] CGI help

2005-01-03 Thread David Holland
I have written my first cgi script :-
The .html code is :-

Friends CGI Demo (Static Screen)

Friends list for:New User

Enter your name>

How many friends do you have ?
0
10
25
50
100

The python code is :-
#!/usr/bin/env python
import cgi
reshtml = '''Content-Type: text/html\n

Friends CGI Demo (dynamic screen)

Friends list for: %s
Your name is: %s
You have %s friends.
'''
form = cgi.FieldStorage()
who = form['person'].value
howmany = form['howmany'].value
print reshtml % (who, who, howmany)


Now when I open the page using konqueror and click on
submit. Instead of the code running, it justs opens
the .py program in a different window.
Any ideas ? 





___ 
ALL-NEW Yahoo! Messenger - all new features - even more fun! 
http://uk.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor