Question -- Running Programming Python Examples

chernevik at gmail.com chernevik at gmail.com
Sat Aug 4 17:30:07 EDT 2007


Here is a newbie question: how do I get the server examples in the
Preview chapter of  "Progamming Python" (Lutz) to run?  The code is
supposed to be a little webserver on which to run examples, but when I
run it it I get "permission denied".  Running it as root gets "address
already in use".

Here is the code (it's example 2.32); comments are from Lutz, not me:

webdir = '.'   # where your html files and cgi-bin script directory
live

port   = 80    # default http://localhost/, else use http://localhost:xxxx/



import os, sys

from BaseHTTPServer import HTTPServer

from CGIHTTPServer  import CGIHTTPRequestHandler



# hack for Windows: os.environ not propogated

[deleted, I'm running linux]
. . .

os.chdir(webdir)                                       # run in html
root dir

srvraddr = ("", port)                                  # my hostname,
portnumber

srvrobj  = HTTPServer(srvraddr, CGIHTTPRequestHandler)

srvrobj.serve_forever()                                # run as
perpetual demon


END CODE


My other python scripts run fine.

I'm running linux (debian).  I'm not running an webserver (that I know
of anyway).

I've fiddled with adding the subdirectory with the code to the python
path, but this doesn't seem to help either.  I'm new to all this, but
I've been able to make the other stuff work, and I can't even find the
beginning of what I'm supposed to research to fix this.

Any help would be greatly appreciated, and thanks for your time and
patience.




More information about the Python-list mailing list