20.7. httplib — HTTP protocol client¶
Note
The httplib module has been renamed to http.client in Python
3.0. The 2to3 tool will automatically adapt imports when converting
your sources to 3.0.
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.
Note
The public interface for this module changed substantially in Python 2.0. The
HTTP class is retained only for backward compatibility with 1.5.2. It
should not be used in new code. Refer to the online docstrings for usage.
The module provides the following classes:
-
class
httplib.HTTPConnection(host[, port[, strict[, timeout]]])¶ An
HTTPConnectioninstance 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 formhost:port, else the default HTTP port (80) is used. When True, the optional parameter strict (which defaults to a false value) causesBadStatusLineto be raised if the status line can’t be parsed as a valid HTTP/1.0 or 1.1 status line. If the optional timeout parameter is given, blocking operations (like connection attempts) will timeout after that many seconds (if it is not given, the global default timeout setting 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) >>> h3 = httplib.HTTPConnection('www.cwi.nl', 80, timeout=10)
New in version 2.0:
New in version 2.0.
Changed in version 2.6:
Changed in version 2.6: timeout was added.