httplib
index
/usr/local/lib/python2.4/httplib.py
Module Docs

HTTP/1.1 client library
 
<intro stuff goes here>
<other stuff, too>
 
HTTPConnection go through a number of "states", which defines when a client
may legally make another request or fetch the response for a particular
request. This diagram details these state transitions:
 
    (null)
      |
      | HTTPConnection()
      v
    Idle
      |
      | putrequest()
      v
    Request-started
      |
      | ( putheader() )*  endheaders()
      v
    Request-sent
      |
      | response = getresponse()
      v
    Unread-response   [Response-headers-read]
      |\____________________
      |                     |
      | response.read()     | putrequest()
      v                     v
    Idle                  Req-started-unread-response
                     ______/|
                   /        |
   response.read() |        | ( putheader() )*  endheaders()
                   v        v
       Request-started    Req-sent-unread-response
                            |
                            | response.read()
                            v
                          Request-sent
 
This diagram presents the following rules:
  -- a second request may not be started until {response-headers-read}
  -- a response [object] cannot be retrieved until {request-sent}
  -- there is no differentiation between an unread response body and a
     partially read response body
 
Note: this enforcement is applied by the HTTPConnection class. The
      HTTPResponse class does not enforce this state machine, which
      implies sophisticated clients may accelerate the request/response
      pipeline. Caution should be taken, though: accelerating the states
      beyond the above pattern may imply knowledge of the server's
      connection-close behavior for certain requests. For example, it
      is impossible to tell whether the server will close the connection
      UNTIL the response headers have been read; this means that further
      requests cannot be placed into the pipeline until it is known that
      the server will NOT be closing the connection.
 
Logical State                  __state            __response
-------------                  -------            ----------
Idle                           _CS_IDLE           None
Request-started                _CS_REQ_STARTED    None
Request-sent                   _CS_REQ_SENT       None
Unread-response                _CS_IDLE           <response_class>
Req-started-unread-response    _CS_REQ_STARTED    <response_class>
Req-sent-unread-response       _CS_REQ_SENT       <response_class>

 
Modules
       
errno
mimetools
socket

 
Classes
       
exceptions.Exception
HTTPException
BadStatusLine
ImproperConnectionState
CannotSendHeader
CannotSendRequest
ResponseNotReady
IncompleteRead
InvalidURL
NotConnected
UnimplementedFileMode
UnknownProtocol
UnknownTransferEncoding
HTTPException
BadStatusLine
ImproperConnectionState
CannotSendHeader
CannotSendRequest
ResponseNotReady
IncompleteRead
InvalidURL
NotConnected
UnimplementedFileMode
UnknownProtocol
UnknownTransferEncoding
HTTP
HTTPConnection
HTTPSConnection
HTTPResponse

 
class BadStatusLine(HTTPException)
    
Method resolution order:
BadStatusLine
HTTPException
exceptions.Exception

Methods defined here:
__init__(self, line)

Methods inherited from exceptions.Exception:
__getitem__(...)
__str__(...)

 
class CannotSendHeader(ImproperConnectionState)
    
Method resolution order:
CannotSendHeader
ImproperConnectionState
HTTPException
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class CannotSendRequest(ImproperConnectionState)
    
Method resolution order:
CannotSendRequest
ImproperConnectionState
HTTPException
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class HTTP
    Compatibility class with httplib.py from 1.5.
 
  Methods defined here:
__init__(self, host='', port=None, strict=None)
Provide a default host, since the superclass requires one.
close(self)
connect(self, host=None, port=None)
Accept arguments to set the host/port, since the superclass doesn't.
getfile(self)
Provide a getfile, since the superclass' does not use this concept.
getreply(self)
Compat definition since superclass does not define it.
 
Returns a tuple consisting of:
- server status code (e.g. '200' if all goes well)
- server "reason" corresponding to status code
- any RFC822 headers in the response from the server
putheader(self, header, *values)
The superclass allows only one value argument.

Data and other attributes defined here:
debuglevel = 0

 
class HTTPConnection
     Methods defined here:
__init__(self, host, port=None, strict=None)
close(self)
Close the connection to the HTTP server.
connect(self)
Connect to the host and port specified in __init__.
endheaders(self)
Indicate that the last header line has been sent to the server.
getresponse(self)
Get the response from the server.
putheader(self, header, value)
Send a request header line to the server.
 
For example: h.putheader('Accept', 'text/html')
putrequest(self, method, url, skip_host=0, skip_accept_encoding=0)
Send a request to the server.
 
`method' specifies an HTTP request method, e.g. 'GET'.
`url' specifies the object being requested, e.g. '/index.html'.
`skip_host' if True does not add automatically a 'Host:' header
`skip_accept_encoding' if True does not add automatically an
   'Accept-Encoding:' header
request(self, method, url, body=None, headers={})
Send a complete request to the server.
send(self, str)
Send `str' to the server.
set_debuglevel(self, level)

Data and other attributes defined here:
auto_open = 1
debuglevel = 0
default_port = 80
response_class = <class httplib.HTTPResponse>
strict = 0

 
class HTTPException(exceptions.Exception)
     Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class HTTPResponse
     Methods defined here:
__init__(self, sock, debuglevel=0, strict=0, method=None)
begin(self)
close(self)
getheader(self, name, default=None)
getheaders(self)
Return list of (header, value) tuples.
isclosed(self)
read(self, amt=None)

 
class HTTPSConnection(HTTPConnection)
    This class allows communication via SSL.
 
  Methods defined here:
__init__(self, host, port=None, key_file=None, cert_file=None, strict=None)
connect(self)
Connect to a host on a given (SSL) port.

Data and other attributes defined here:
default_port = 443

Methods inherited from HTTPConnection:
close(self)
Close the connection to the HTTP server.
endheaders(self)
Indicate that the last header line has been sent to the server.
getresponse(self)
Get the response from the server.
putheader(self, header, value)
Send a request header line to the server.
 
For example: h.putheader('Accept', 'text/html')
putrequest(self, method, url, skip_host=0, skip_accept_encoding=0)
Send a request to the server.
 
`method' specifies an HTTP request method, e.g. 'GET'.
`url' specifies the object being requested, e.g. '/index.html'.
`skip_host' if True does not add automatically a 'Host:' header
`skip_accept_encoding' if True does not add automatically an
   'Accept-Encoding:' header
request(self, method, url, body=None, headers={})
Send a complete request to the server.
send(self, str)
Send `str' to the server.
set_debuglevel(self, level)

Data and other attributes inherited from HTTPConnection:
auto_open = 1
debuglevel = 0
response_class = <class httplib.HTTPResponse>
strict = 0

 
class ImproperConnectionState(HTTPException)
    
Method resolution order:
ImproperConnectionState
HTTPException
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class IncompleteRead(HTTPException)
    
Method resolution order:
IncompleteRead
HTTPException
exceptions.Exception

Methods defined here:
__init__(self, partial)

Methods inherited from exceptions.Exception:
__getitem__(...)
__str__(...)

 
class InvalidURL(HTTPException)
    
Method resolution order:
InvalidURL
HTTPException
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class NotConnected(HTTPException)
    
Method resolution order:
NotConnected
HTTPException
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class ResponseNotReady(ImproperConnectionState)
    
Method resolution order:
ResponseNotReady
ImproperConnectionState
HTTPException
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class UnimplementedFileMode(HTTPException)
    
Method resolution order:
UnimplementedFileMode
HTTPException
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class UnknownProtocol(HTTPException)
    
Method resolution order:
UnknownProtocol
HTTPException
exceptions.Exception

Methods defined here:
__init__(self, version)

Methods inherited from exceptions.Exception:
__getitem__(...)
__str__(...)

 
class UnknownTransferEncoding(HTTPException)
    
Method resolution order:
UnknownTransferEncoding
HTTPException
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
error = class HTTPException(exceptions.Exception)
     Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
Data
        __all__ = ['HTTP', 'HTTPResponse', 'HTTPConnection', 'HTTPSConnection', 'HTTPException', 'NotConnected', 'UnknownProtocol', 'UnknownTransferEncoding', 'UnimplementedFileMode', 'IncompleteRead', 'InvalidURL', 'ImproperConnectionState', 'CannotSendRequest', 'CannotSendHeader', 'ResponseNotReady', 'BadStatusLine', 'error']