473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Question -- Running Programming Python Examples

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.

Aug 4 '07 #1
3 1861
ch*******@gmail.com wrote:
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".
The first error is because non-root users cannot bind to ports lower
than 1024. The second error means just what it says: The address is
already in use, so you can't bind to port 80. Something else is already
bound to it; probably you have an HTTP server already running as part of
your default software installation and don't realize it.

Choose another port.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
If love is the answer, could you rephrase the question?
-- Lily Tomlin
Aug 4 '07 #2
ch*******@gmail.com wrote:
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/
There's the trouble. You need special permission to open any of the
ports up through 1023. As root, you have permission, but apparently
some process already has that port opened, almost certainly a web server
you start up at boot time, probably apache.

So either kill off the web server that has port 80 opened, or better
yet, just change the port to something else. A common choice is port
8080. This does not require superuser permission, and is probably free.
port = 8080

If you do that, then you access the server on port 8080 with url's that
look like this:

http://localhost:8080/what/ever/..., or
http://machine-name:8080/what/ever/...,

Gary Herron
>

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.

Aug 4 '07 #3
That fixed it, and Gary's item on pointing my browser to the proper
port answered the next question percolating in my mind. It now runs
as advertised.

Thanks to you both!
Aug 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Fernando Rodriguez | last post by:
Hi, Any recommendation for a good book on multithreaded programming with Python? O:-) TIA
4
by: Mark | last post by:
Hello. I am new to programming and Python and was wondering if someone could help get me started. I picked Python to start learning to prgram because of some things I have read about it (easy to...
6
by: bobdc | last post by:
I will be teaching an "Introduction to Programming" class to some middle school aged children and will be using Python, obviously. Does anyone have suggestions for simple little programs to create...
3
by: Edg Bamyasi | last post by:
This Is A Late Cross Post from comp.lang.python. It seems the mistery is deeper then i expected. What is the running time of conactination on character strings. i.e. >> joe="123" >>...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
26
by: Kevin Walzer | last post by:
....with a twist. I'm undertaking my first semi-substantial Python GUI application after a long time dabbling with the language. I'm fairly experienced with Tcl/Tk, so Tkinter seems the...
78
by: wkehowski | last post by:
The python code below generates a cartesian product subject to any logical combination of wildcard exclusions. For example, suppose I want to generate a cartesian product S^n, n>=3, of that...
90
by: John Salerno | last post by:
I'm a little confused. Why doesn't s evaluate to True in the first part, but it does in the second? Is the first statement something different? False print 'hi' hi Thanks.
25
by: Nicholas Parsons | last post by:
Howdy Folks, I was just playing around in IDLE at the interactive prompt and typed in dir({}) for the fun of it. I was quite surprised to see a pop method defined there. I mean is that a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.