[Tutor] Apache, CGI-BIN, Python

Steve Willoughby steve at alchemy.com
Mon Sep 10 00:02:19 CEST 2007


Ryan wrote:
> I am running a Linux box and cannot find my Apache cgi-bin to put some 
> python scripts in. I know I probably have to create one but don't know 
> where and how.

On Linux under Apache 2.2, I've seen it in /usr/lib/cgi-bin which always 
struck me as weird, but there you go.  On BSD, it tends to live in 
/var/www/cgi-bin.

YMMV.

> 
> Also on my windows machine,where I do have the bin, and normally 
> everything works fine except:
> 
> #!c:/Python25/python
> import cgi
> 
> reshtml = """Content-type: text/html\n\n"
> <html>
> <head><title>Hello Python</title></head>
> 
> <body>
> <h1>Welcome To A Python Script!</h1>
> </body>
> </html>"""
> 
> form = cgi.FieldStorage()
> 
> #This is where everything goes wrong
> #I get error messages for either the lastname line or firstname
> 
> lastname = form['lastname'].value
> firstname =form['firstname'].value

What error message do you get?  I'd recommend, actually, using 
form.getfirst('lastname') instead.  It's more robust in case there are 
multiple occurrences of a field on the form the user submits.

You can also check to see if the form even has the fields you're trying 
to read, but again, knowing what error message you're getting would be 
very helpful to point you in the right direction on this.

> message = firstname + " " + lastname
> print reshtml % message

I think you need a %s or something in the reshtml string, too.





More information about the Tutor mailing list