The httplib Module (cont)

Making an HTTP connection

     import httplib
     h = httplib.HTTP("www.python.org")
     h.putrequest('GET','/index.html')
     h.putheader('User-Agent','Lame Tutorial Code')
     h.putheader('Accept','text/html')
     h.endheaders()
     errcode,errmsg, headers = h.getreply()
     f = h.getfile()   # Get file object for reading data
     data = f.read()
     f.close() 

Comments

  • Some understanding of HTTP is required.
  • Only HTTP/1.0 is currently supported.
  • Most of the other protocol modules work in a similar manner.
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 94
July 17, 2000, beazley@cs.uchicago.edu
>>>