pseudocode,” systems are sometimes better described in Python than in English once
you have the overall design in mind.
Running This Chapter’s Examples
The HTML pages and CGI scripts of PyMailCGI can be installed on any web server to
which you have access. To keep things simple for this book, though, we’re going to use
the same policy as in Chapter 15—we’ll be running the Python-coded webserver.py
script from Example 16-1 locally, on the same machine as the web browser client. As
we learned at the start of the prior chapter, that means we’ll be using the server domain
name “localhost” (or the equivalent IP address, “127.0.0.1”) to access this system’s
pages in our browser, as well as in the urllib.request module.
Start this server script on your own machine to test-drive the program. Ultimately, this
system must generally contact a mail server over the Internet to fetch or send messages,
but the web page server will be running locally on your computer.
One minor twist here: PyMailCGI’s code is located in a directory of its own, one level
down from the webserver.py script. Because of that, we’ll start the web server here with
an explicit directory and port number in the command line used to launch it:
C:\...\PP4E\Internet\Web> webserver.py PyMailCgi 8000
Type this sort of command into a command prompt window on Windows or into your
system shell prompt on Unix-like platforms. When run this way, the server will listen
for URL requests on machine “localhost” and socket port number 8000. It will serve
up pages from the PyMailCgi subdirectory one level below the script’s location, and it
will run CGI scripts located in the PyMailCgi\cgi-bin directory below that. This works
because the script changes its current working directory to the one you name when it
starts up.
Subtle point: because we specify a unique port number on the command line this way,
it’s OK if you simultaneously run another instance of the script to serve up the prior
chapter’s examples one directory up; that server instance will accept connections on
port 80, and our new instance will handle requests on port 8000. In fact, you can contact
either server from the same browser by specifying the desired server’s port number. If
you have two instances of the server running in the two different chapters’ directories,
to access pages and scripts of the prior chapter, use a URL of this form:
http://localhost/languages.html
http://localhost/cgi-bin/languages.py?language=All
And to run this chapter’s pages and scripts, simply use URLs of this form:
http://localhost:8000/pymailcgi.html
http://localhost:8000/cgi-bin/onRootSendLink.py
You’ll see that the HTTP and CGI log messages appear in the window of the server
you’re contacting. For more background on why this works as it does, see the
The PyMailCGI Website | 1237