<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <link rel="STYLESHEET" href="lib.css" type='text/css' /> <link rel="SHORTCUT ICON" href="../icons/pyfav.gif" /> <link rel='start' href='../index.html' title='Python Documentation Index' /> <link rel="first" href="lib.html" title='Python Library Reference' /> <link rel='contents' href='contents.html' title="Contents" /> <link rel='index' href='genindex.html' title='Index' /> <link rel='last' href='about.html' title='About this document...' /> <link rel='help' href='about.html' title='About this document...' /> <LINK rel="next" href="module-ftplib.html"> <LINK rel="prev" href="module-urllib2.html"> <LINK rel="parent" href="internet.html"> <LINK rel="next" href="httpconnection-objects.html"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name='aesop' content='information' /> <META name="description" content="httplib -- HTTP protocol client"> <META name="keywords" content="lib"> <META name="resource-type" content="document"> <META name="distribution" content="global"> <title>11.6 httplib -- HTTP protocol client</title> </head> <body> <DIV CLASS="navigation"> <div id='top-navigation-panel'> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="11.5.20 Examples" href="urllib2-examples.html"><img src='../icons/previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="11. Internet Protocols and" href="internet.html"><img src='../icons/up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="11.6.1 HTTPConnection Objects" href="httpconnection-objects.html"><img src='../icons/next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Python Library Reference</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" href="contents.html"><img src='../icons/contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' border='0' height='32' alt='Module Index' width='32' /></a></td> <td class='online-navigation'><a rel="index" title="Index" href="genindex.html"><img src='../icons/index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="urllib2-examples.html">11.5.20 Examples</A> <b class="navlabel">Up:</b> <a class="sectref" rel="parent" href="internet.html">11. Internet Protocols and</A> <b class="navlabel">Next:</b> <a class="sectref" rel="next" href="httpconnection-objects.html">11.6.1 HTTPConnection Objects</A> </div> <hr /></div> </DIV> <!--End of Navigation Panel--> <H1><A NAME="SECTION0013600000000000000000"> 11.6 <tt class="module">httplib</tt> -- HTTP protocol client</A> </H1> <P> <A NAME="module-httplib"><!--z--></A> <P> <a id='l2h-3087'><!--x--></a><a id='l2h-3105'><!--x--></a> <P> This module defines classes which implement the client side of the HTTP and HTTPS protocols. It is normally not used directly -- the module <tt class="module"><a href="module-urllib.html">urllib</a></tt><a id='l2h-3106'><!--x--></a> uses it to handle URLs that use HTTP and HTTPS. <P> <div class="note"><b class="label">Note:</b> HTTPS support is only available if the <tt class="module"><a href="module-socket.html">socket</a></tt> module was compiled with SSL support. </div> <P> <div class="note"><b class="label">Note:</b> The public interface for this module changed substantially in Python 2.0. The <tt class="class">HTTP</tt> 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. </div> <P> The constants defined in this module are: <P> <dl><dt><b><tt id='l2h-3088'>HTTP_PORT</tt></b></dt> <dd> The default port for the HTTP protocol (always <code>80</code>). </dd></dl> <P> <dl><dt><b><tt id='l2h-3089'>HTTPS_PORT</tt></b></dt> <dd> The default port for the HTTPS protocol (always <code>443</code>). </dd></dl> <P> The module provides the following classes: <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3090' class="class">HTTPConnection</tt></b>(</nobr></td> <td><var>host</var><big>[</big><var>, port</var><big>]</big>)</td></tr></table></dt> <dd> An <tt class="class">HTTPConnection</tt> 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 <code><var>host</var>:<var>port</var></code>, 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: <P> <div class="verbatim"><pre> >>> h1 = httplib.HTTPConnection('www.cwi.nl') >>> h2 = httplib.HTTPConnection('www.cwi.nl:80') >>> h3 = httplib.HTTPConnection('www.cwi.nl', 80) </pre></div> <span class="versionnote">New in version 2.0.</span> </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3091' class="class">HTTPSConnection</tt></b>(</nobr></td> <td><var>host</var><big>[</big><var>, port, key_file, cert_file</var><big>]</big>)</td></tr></table></dt> <dd> A subclass of <tt class="class">HTTPConnection</tt> that uses SSL for communication with secure servers. Default port is <code>443</code>. <var>key_file</var> is the name of a PEM formatted file that contains your private key. <var>cert_file</var> is a PEM formatted certificate chain file. <P> <span class="warning"><b class="label">Warning:</b> This does not do any certificate verification!</span> <P> <span class="versionnote">New in version 2.0.</span> </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3092' class="class">HTTPResponse</tt></b>(</nobr></td> <td><var>sock</var><big>[</big><var>, debuglevel=0</var><big>]</big><big>[</big><var>, strict=0</var><big>]</big>)</td></tr></table></dt> <dd> Class whose instances are returned upon successful connection. Not instantiated directly by user. <span class="versionnote">New in version 2.0.</span> </dl> <P> The following exceptions are raised as appropriate: <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3093' class="exception">HTTPException</tt></b></dt> <dd> The base class of the other exceptions in this module. It is a subclass of <tt class="exception">Exception</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3094' class="exception">NotConnected</tt></b></dt> <dd> A subclass of <tt class="exception">HTTPException</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3095' class="exception">InvalidURL</tt></b></dt> <dd> A subclass of <tt class="exception">HTTPException</tt>, raised if a port is given and is either non-numeric or empty. <span class="versionnote">New in version 2.3.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3096' class="exception">UnknownProtocol</tt></b></dt> <dd> A subclass of <tt class="exception">HTTPException</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3097' class="exception">UnknownTransferEncoding</tt></b></dt> <dd> A subclass of <tt class="exception">HTTPException</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3098' class="exception">UnimplementedFileMode</tt></b></dt> <dd> A subclass of <tt class="exception">HTTPException</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3099' class="exception">IncompleteRead</tt></b></dt> <dd> A subclass of <tt class="exception">HTTPException</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3100' class="exception">ImproperConnectionState</tt></b></dt> <dd> A subclass of <tt class="exception">HTTPException</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3101' class="exception">CannotSendRequest</tt></b></dt> <dd> A subclass of <tt class="exception">ImproperConnectionState</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3102' class="exception">CannotSendHeader</tt></b></dt> <dd> A subclass of <tt class="exception">ImproperConnectionState</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3103' class="exception">ResponseNotReady</tt></b></dt> <dd> A subclass of <tt class="exception">ImproperConnectionState</tt>. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <dl><dt><b><span class="typelabel">exception</span> <tt id='l2h-3104' class="exception">BadStatusLine</tt></b></dt> <dd> A subclass of <tt class="exception">HTTPException</tt>. Raised if a server responds with a HTTP status code that we don't understand. <span class="versionnote">New in version 2.0.</span> </dd></dl> <P> <p><br /></p><hr class='online-navigation' /> <div class='online-navigation'> <!--Table of Child-Links--> <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> <UL CLASS="ChildLinks"> <LI><A href="httpconnection-objects.html">11.6.1 HTTPConnection Objects</a> <LI><A href="httpresponse-objects.html">11.6.2 HTTPResponse Objects</a> <LI><A href="httplib-examples.html">11.6.3 Examples</a> </ul> <!--End of Table of Child-Links--> </div> <DIV CLASS="navigation"> <div class='online-navigation'><hr /> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="11.5.20 Examples" rel="prev" title="11.5.20 Examples" href="urllib2-examples.html"><img src='../icons/previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="11. Internet Protocols and" rel="parent" title="11. Internet Protocols and" href="internet.html"><img src='../icons/up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="11.6.1 HTTPConnection Objects" rel="next" title="11.6.1 HTTPConnection Objects" href="httpconnection-objects.html"><img src='../icons/next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Python Library Reference</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" rel="contents" title="Table of Contents" href="contents.html"><img src='../icons/contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' border='0' height='32' alt='Module Index' width='32' /></a></td> <td class='online-navigation'><a rel="index" title="Index" rel="index" title="Index" href="genindex.html"><img src='../icons/index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="urllib2-examples.html">11.5.20 Examples</A> <b class="navlabel">Up:</b> <a class="sectref" rel="parent" href="internet.html">11. Internet Protocols and</A> <b class="navlabel">Next:</b> <a class="sectref" rel="next" href="httpconnection-objects.html">11.6.1 HTTPConnection Objects</A> </div> </div> <hr /> <span class="release-info">Release 2.3.4, documentation updated on May 20, 2004.</span> </DIV> <!--End of Navigation Panel--> <ADDRESS> See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. </ADDRESS> </BODY> </HTML>