[Tutor] CGI help

Rich Krauter rmkrauter at yahoo.com
Wed Jan 5 02:43:19 CET 2005


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



<<server.py>>

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()

<</server.py>>


<<dh.py>>

#!C:/Python24/python.exe

print "Content-Type: text/html"
print

import cgi,cgitb
cgitb.enable()

reshtml = '''
<html>
<head>
<title>CGI Demo</title>
</head>
<body>
<h3>Friends list for:%s</h3>
Your name is: <b>%s</b><br>
You have <b>%s</b> friends.
</body>
</html>'''

form = cgi.FieldStorage()
who = form.getfirst('person')
howmany = form.getfirst('howmany')

print reshtml % (who, who, howmany)

<</dh.py>>



<<form.html>>

<html>
<head>
<title>
CGI Demo
</title>
</head>

<body>

<h3>Friends list for New User</h3>
<form method="get" action="/cgi-bin/dh.py">
<b>Enter your name</b><input type="text" name="person" size=15><br>
<b>How many friends do you have?</b>
<input type="radio" name="howmany" value="0" checked>0
<input type="radio" name="howmany" value="10">10
<input type="radio" name="howmany" value="25">25
<input type="radio" name="howmany" value="50">50
<input type="radio" name="howmany" value="100">100><br>
<input type="submit">
</form>

</body>

</html>

<<form.html>>






More information about the Tutor mailing list