11.6 httplib -- HTTP protocol client

 

This module defines classes which implement the client side of the HTTP and HTTPS protocols. It is normally not used directly -- the module urllib uses it to handle URLs that use HTTP and HTTPS. Note: HTTPS support is only available if the socket module was compiled with SSL support.

The constants defined in this module are:

HTTP_PORT
The default port for the HTTP protocol (always 80).

HTTPS_PORT
The default port for the HTTPS protocol (always 443).

The module provides the following classes:

class HTTPConnection(host[, port])
An HTTPConnection instance represents one transaction with an HTTP server. It should be instantiated passing it a host and optional port number. If no port number is passed, the port is extracted from the host string if it has the form host:port, else the default HTTP port (80) is used. For example, the following calls all create instances that connect to the server at the same host and port:

>>> h1 = httplib.HTTPConnection('www.cwi.nl')
>>> h2 = httplib.HTTPConnection('www.cwi.nl:80')
>>> h3 = httplib.HTTPConnection('www.cwi.nl', 80)

class HTTPSConnection(host[, port, key_file, cert_file])
A subclass of HTTPConnection that uses SSL for communication with secure servers. Default port is 443. key_file is the name of a PEM formatted file that contains your private key. cert_file is a PEM formatted certificate chain file.

Warning: This does not do any certificate verification!

The following exceptions are raised as appropriate:

exception HTTPException
The base class of the other exceptions in this module. It is a subclass of Exception.

exception NotConnected
A subclass of HTTPException.

exception UnknownProtocol
A subclass of HTTPException.

exception UnknownTransferEncoding
A subclass of HTTPException.

exception IllegalKeywordArgument
A subclass of HTTPException.

exception UnimplementedFileMode
A subclass of HTTPException.

exception IncompleteRead
A subclass of HTTPException.

exception ImproperConnectionState
A subclass of HTTPException.

exception CannotSendRequest
A subclass of ImproperConnectionState.

exception CannotSendHeader
A subclass of ImproperConnectionState.

exception ResponseNotReady
A subclass of ImproperConnectionState.

exception BadStatusLine
A subclass of HTTPException. Raised if a server responds with a HTTP status code that we don't understand.


Subsections
See About this document... for information on suggesting changes.