b'\n'
b'\n'
b'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n'
b'\n'
b'<head>\n'
C:\...\PP4E\Internet\Other> http-getfile.py http://www.python.org index.html
http://www.python.org index.html
Error sending request 400 Bad Request
C:\...\PP4E\Internet\Other> http-getfile.py http://www.rmi.net /~lutz
http://www.rmi.net /~lutz
Error sending request 301 Moved Permanently
C:\...\PP4E\Internet\Other> http-getfile.py http://www.rmi.net /~lutz/index.html
http://www.rmi.net /~lutz/index.html
b'<HTML>\n'
b'\n'
b'<HEAD>\n'
b"<TITLE>Mark Lutz's Book Support Site</TITLE>\n"
b'</HEAD>\n'
b'<BODY BGCOLOR="#f1f1ff">\n'
Notice the second and third attempts in this code: if the request fails, the script receives
and displays an HTTP error code from the server (we forgot the leading slash on the
second, and the “index.html” on the third—required for this server and interface). With
the raw HTTP interfaces, we need to be precise about what we want.
Technically, the string we call filename in the script can refer to either a simple static
web page file or a server-side program that generates HTML as its output. Those server-
side programs are usually called CGI scripts—the topic of Chapters 15 and 16. For
now, keep in mind that when filename refers to a script, this program can be used to
invoke another program that resides on a remote server machine. In that case, we can
also specify parameters (called a query string) to be passed to the remote program after
a ?.
Here, for instance, we pass a language=Python parameter to a CGI script we will meet
in Chapter 15 (to make this work, we also need to first spawn a locally running HTTP
web server coded in Python using a script we first met in Chapter 1 and will revisit in
Chapter 15):
In a different window
C:\...\PP4E\Internet\Web> webserver.py
webdir ".", port 80
C:\...\PP4E\Internet\Other> http-getfile.py localhost
/cgi-bin/languages.py?language=Python
localhost /cgi-bin/languages.py?language=Python
b'<TITLE>Languages</TITLE>\n'
b'<H1>Syntax</H1><HR>\n'
b'<H3>Python</H3><P><PRE>\n'
b" print('Hello World') \n"
996 | Chapter 13: Client-Side Scripting