1. Computing

Building a Web Client in Python

From , former About.com Guide

7 of 9

Python Asks the Web Server for the File

Now we get to communicate with the server. In retrieving information from a web server, web browsers send their requests in the following format:

<type of request> <file name> <protocol to use>

Our web client will ask the server to "GET" a given file using the HTTP 1.0 protocol. To communcate this, we write to the file-like object of the socket instance:


fileobj.write("GET "+filename+" HTTP/1.0\n\n")

The server will then respond with the data, and that data will be buffered as a file-like object. But our program will not get it unless we read it. So read the file object into another variable, here called buff.


buff = fileobj.readlines()

  1. About.com
  2. Computing
  3. Python
  4. Networking
  5. Programming a Python Web Client : Python Asks the Web Server for the File

©2013 About.com. All rights reserved.