473,591 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CGIHTTPRequestH andler

# 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(srvr addr, CGIHTTPRequestH andler)

srvrobj.serve_f orever() # 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 1873
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 CGIHTTPRequestH andler

# 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(srvr addr, CGIHTTPRequestH andler)

srvrobj.serve_f orever() # 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
3277
by: Fernando Rodriguez | last post by:
Hi, Any recommendation for a good book on multithreaded programming with Python? O:-) TIA
4
2418
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 learn, object oriented, clear syntax, etc...). Can anyone assist in getting me started with learning to program and Python? Recommended reading material? Online tutorials? Recommended development tools (wxpython, pythonwin, etc...)? I am a...
6
4055
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 and analyze with them after I get past turtle graphics? Turtle graphics will be plenty for the first session, and I will leave time to ask them what they'd like to do in later sessions, but I was curious if anyone on the list has experience...
3
2305
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" >> joe+="99999999999999999"
44
4179
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 must be many know the answer here. thanks
26
1897
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 obvious choice to reduce my Python learning curve. However, my Tcl applications typically make use of a *lot* of extensions to the core widget set, such as BWidgets, tablelist, and Tile.
78
4573
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 excludes '*a*b*' and '*c*d*a*'. See below for details. CHALLENGE: generate an equivalent in ruby, lisp, haskell, ocaml, or in a CAS like maple or mathematica. #------------------------------------------------------------------------------- # Short...
90
3394
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
4188
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 misnomer or what? From the literature, pop is supposed to be an operation defined for a stack data structure. A stack is defined to be an "ordered" list data structure. Dictionaries in Python have no order but are sequences. Now, does anyone know...
0
7870
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7992
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8225
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6639
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5732
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3891
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.