| 
									
										
										
										
											1998-08-10 19:42:37 +00:00
										 |  |  | \section{\module{httplib} --- | 
					
						
							| 
									
										
										
										
											1999-04-22 16:47:27 +00:00
										 |  |  |          HTTP protocol client} | 
					
						
							| 
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-04-22 16:47:27 +00:00
										 |  |  | \declaremodule{standard}{httplib} | 
					
						
							| 
									
										
										
										
											2001-09-25 16:32:02 +00:00
										 |  |  | \modulesynopsis{HTTP and HTTPS protocol client (requires sockets).} | 
					
						
							| 
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-12 05:54:02 +00:00
										 |  |  | \indexii{HTTP}{protocol} | 
					
						
							| 
									
										
										
										
											2001-12-26 19:48:43 +00:00
										 |  |  | \index{HTTP!\module{httplib} (standard module)} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-25 16:32:02 +00:00
										 |  |  | This module defines classes which implement the client side of the | 
					
						
							|  |  |  | HTTP and HTTPS protocols.  It is normally not used directly --- the | 
					
						
							|  |  |  | module \refmodule{urllib}\refstmodindex{urllib} uses it to handle URLs | 
					
						
							| 
									
										
										
										
											2003-01-27 16:32:04 +00:00
										 |  |  | that use HTTP and HTTPS. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{notice} | 
					
						
							|  |  |  |   HTTPS support is only available if the \refmodule{socket} module was | 
					
						
							|  |  |  |   compiled with SSL support. | 
					
						
							|  |  |  | \end{notice} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{notice} | 
					
						
							|  |  |  |   The public interface for this module changed substantially in Python | 
					
						
							|  |  |  |   2.0.  The \class{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. | 
					
						
							|  |  |  | \end{notice} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | The module provides the following classes: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{classdesc}{HTTPConnection}{host\optional{, port}} | 
					
						
							|  |  |  | An \class{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 \code{\var{host}:\var{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: | 
					
						
							| 
									
										
										
										
											1995-03-17 16:07:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-02-13 06:58:54 +00:00
										 |  |  | \begin{verbatim} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | >>> h1 = httplib.HTTPConnection('www.cwi.nl') | 
					
						
							|  |  |  | >>> h2 = httplib.HTTPConnection('www.cwi.nl:80') | 
					
						
							|  |  |  | >>> h3 = httplib.HTTPConnection('www.cwi.nl', 80) | 
					
						
							| 
									
										
										
										
											1998-02-13 06:58:54 +00:00
										 |  |  | \end{verbatim} | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{classdesc} | 
					
						
							| 
									
										
										
										
											1998-03-12 05:54:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-05-20 02:56:35 +00:00
										 |  |  | \begin{classdesc}{HTTPSConnection}{host\optional{, port, key_file, cert_file}} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | A subclass of \class{HTTPConnection} that uses SSL for communication with | 
					
						
							|  |  |  | secure servers.  Default port is \code{443}. | 
					
						
							| 
									
										
										
										
											2003-05-20 02:56:35 +00:00
										 |  |  | \var{key_file} is | 
					
						
							|  |  |  | the name of a PEM formatted file that contains your private | 
					
						
							|  |  |  | key. \var{cert_file} is a PEM formatted certificate chain file. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \warning{This does not do any certificate verification!} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							|  |  |  | \end{classdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{classdesc}{HTTPResponse}{sock\optional{, debuglevel=0}\optional{, strict=0}} | 
					
						
							|  |  |  | Class whose instances are returned upon successful connection.  Not | 
					
						
							|  |  |  | instantiated directly by user. | 
					
						
							|  |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{classdesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | The following exceptions are raised as appropriate: | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{HTTPException} | 
					
						
							|  |  |  | The base class of the other exceptions in this module.  It is a | 
					
						
							|  |  |  | subclass of \exception{Exception}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{NotConnected} | 
					
						
							|  |  |  | A subclass of \exception{HTTPException}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-03-24 16:55:57 +00:00
										 |  |  | \begin{excdesc}{InvalidURL} | 
					
						
							|  |  |  | A subclass of \exception{HTTPException}, raised if a port is given and is | 
					
						
							|  |  |  | either non-numeric or empty. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.3} | 
					
						
							| 
									
										
										
										
											2002-03-24 16:55:57 +00:00
										 |  |  | \end{excdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{UnknownProtocol} | 
					
						
							|  |  |  | A subclass of \exception{HTTPException}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{UnknownTransferEncoding} | 
					
						
							|  |  |  | A subclass of \exception{HTTPException}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{UnimplementedFileMode} | 
					
						
							|  |  |  | A subclass of \exception{HTTPException}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{IncompleteRead} | 
					
						
							|  |  |  | A subclass of \exception{HTTPException}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{ImproperConnectionState} | 
					
						
							|  |  |  | A subclass of \exception{HTTPException}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											2001-11-09 05:03:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{CannotSendRequest} | 
					
						
							|  |  |  | A subclass of \exception{ImproperConnectionState}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											2001-11-09 05:03:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{CannotSendHeader} | 
					
						
							|  |  |  | A subclass of \exception{ImproperConnectionState}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											2001-11-09 05:03:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{ResponseNotReady} | 
					
						
							|  |  |  | A subclass of \exception{ImproperConnectionState}. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											1995-03-28 13:35:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{excdesc}{BadStatusLine} | 
					
						
							|  |  |  | A subclass of \exception{HTTPException}.  Raised if a server responds with a | 
					
						
							|  |  |  | HTTP status code that we don't understand. | 
					
						
							| 
									
										
										
										
											2003-01-27 15:00:38 +00:00
										 |  |  | \versionadded{2.0} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \end{excdesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-18 09:03:49 +00:00
										 |  |  | The constants defined in this module are: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{HTTP_PORT} | 
					
						
							|  |  |  |   The default port for the HTTP protocol (always \code{80}). | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{HTTPS_PORT} | 
					
						
							|  |  |  |   The default port for the HTTPS protocol (always \code{443}). | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | and also the following constants for integer status codes: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{tableiii}{l|c|l}{constant}{Constant}{Value}{Definition} | 
					
						
							|  |  |  |   \lineiii{CONTINUE}{\code{100}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.1.1} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.1}} | 
					
						
							|  |  |  |   \lineiii{SWITCHING_PROTOCOLS}{\code{101}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.1.2} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.2}} | 
					
						
							|  |  |  |   \lineiii{PROCESSING}{\code{102}} | 
					
						
							|  |  |  |     {WEBDAV, \ulink{RFC 2518, Section 10.1} | 
					
						
							|  |  |  |       {http://www.webdav.org/specs/rfc2518.htm#STATUS_102}} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   \lineiii{OK}{\code{200}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.2.1} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.1}} | 
					
						
							|  |  |  |   \lineiii{CREATED}{\code{201}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.2.2} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.2}} | 
					
						
							|  |  |  |   \lineiii{ACCEPTED}{\code{202}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.2.3} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.3}} | 
					
						
							|  |  |  |   \lineiii{NON_AUTHORITATIVE_INFORMATION}{\code{203}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.2.4} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.4}} | 
					
						
							|  |  |  |   \lineiii{NO_CONTENT}{\code{204}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.2.5} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5}} | 
					
						
							|  |  |  |   \lineiii{RESET_CONTENT}{\code{205}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.2.6} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.6}} | 
					
						
							|  |  |  |   \lineiii{PARTIAL_CONTENT}{\code{206}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.2.7} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.7}} | 
					
						
							|  |  |  |   \lineiii{MULTI_STATUS}{\code{207}} | 
					
						
							|  |  |  |     {WEBDAV \ulink{RFC 2518, Section 10.2} | 
					
						
							|  |  |  |       {http://www.webdav.org/specs/rfc2518.htm#STATUS_207}} | 
					
						
							|  |  |  |   \lineiii{IM_USED}{\code{226}} | 
					
						
							|  |  |  |     {Delta encoding in HTTP, \rfc{3229}, Section 10.4.1} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   \lineiii{MULTIPLE_CHOICES}{\code{300}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.3.1} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.1}} | 
					
						
							|  |  |  |   \lineiii{MOVED_PERMANENTLY}{\code{301}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.3.2} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2}} | 
					
						
							|  |  |  |   \lineiii{FOUND}{\code{302}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.3.3} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3}} | 
					
						
							|  |  |  |   \lineiii{SEE_OTHER}{\code{303}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.3.4} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4}} | 
					
						
							|  |  |  |   \lineiii{NOT_MODIFIED}{\code{304}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.3.5} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5}} | 
					
						
							|  |  |  |   \lineiii{USE_PROXY}{\code{305}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.3.6} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.6}} | 
					
						
							|  |  |  |   \lineiii{TEMPORARY_REDIRECT}{\code{307}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.3.8} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8}} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   \lineiii{BAD_REQUEST}{\code{400}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.1} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1}} | 
					
						
							|  |  |  |   \lineiii{UNAUTHORIZED}{\code{401}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.2} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2}} | 
					
						
							|  |  |  |   \lineiii{PAYMENT_REQUIRED}{\code{402}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.3} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.3}} | 
					
						
							|  |  |  |   \lineiii{FORBIDDEN}{\code{403}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.4} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4}} | 
					
						
							|  |  |  |   \lineiii{NOT_FOUND}{\code{404}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.5} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.5}} | 
					
						
							|  |  |  |   \lineiii{METHOD_NOT_ALLOWED}{\code{405}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.6} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6}} | 
					
						
							|  |  |  |   \lineiii{NOT_ACCEPTABLE}{\code{406}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.7} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.7}} | 
					
						
							|  |  |  |   \lineiii{PROXY_AUTHENTICATION_REQUIRED} | 
					
						
							|  |  |  |     {\code{407}}{HTTP/1.1, \ulink{RFC 2616, Section 10.4.8} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.8}} | 
					
						
							|  |  |  |   \lineiii{REQUEST_TIMEOUT}{\code{408}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.9} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.9}} | 
					
						
							|  |  |  |   \lineiii{CONFLICT}{\code{409}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.10} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.10}} | 
					
						
							|  |  |  |   \lineiii{GONE}{\code{410}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.11} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.11}} | 
					
						
							|  |  |  |   \lineiii{LENGTH_REQUIRED}{\code{411}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.12} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.12}} | 
					
						
							|  |  |  |   \lineiii{PRECONDITION_FAILED}{\code{412}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.13} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.13}} | 
					
						
							|  |  |  |   \lineiii{REQUEST_ENTITY_TOO_LARGE} | 
					
						
							|  |  |  |     {\code{413}}{HTTP/1.1, \ulink{RFC 2616, Section 10.4.14} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.14}} | 
					
						
							|  |  |  |   \lineiii{REQUEST_URI_TOO_LONG}{\code{414}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.15} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.15}} | 
					
						
							|  |  |  |   \lineiii{UNSUPPORTED_MEDIA_TYPE}{\code{415}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.16} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16}} | 
					
						
							|  |  |  |   \lineiii{REQUESTED_RANGE_NOT_SATISFIABLE}{\code{416}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.17} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.17}} | 
					
						
							|  |  |  |   \lineiii{EXPECTATION_FAILED}{\code{417}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.4.18} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.18}} | 
					
						
							|  |  |  |   \lineiii{UNPROCESSABLE_ENTITY}{\code{422}} | 
					
						
							|  |  |  |     {WEBDAV, \ulink{RFC 2518, Section 10.3} | 
					
						
							|  |  |  |       {http://www.webdav.org/specs/rfc2518.htm#STATUS_422}} | 
					
						
							|  |  |  |   \lineiii{LOCKED}{\code{423}} | 
					
						
							|  |  |  |     {WEBDAV \ulink{RFC 2518, Section 10.4} | 
					
						
							|  |  |  |       {http://www.webdav.org/specs/rfc2518.htm#STATUS_423}} | 
					
						
							|  |  |  |   \lineiii{FAILED_DEPENDENCY}{\code{424}} | 
					
						
							|  |  |  |     {WEBDAV, \ulink{RFC 2518, Section 10.5} | 
					
						
							|  |  |  |       {http://www.webdav.org/specs/rfc2518.htm#STATUS_424}} | 
					
						
							|  |  |  |   \lineiii{UPGRADE_REQUIRED}{\code{426}} | 
					
						
							|  |  |  |     {HTTP Upgrade to TLS, \rfc{2817}, Section 6} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   \lineiii{INTERNAL_SERVER_ERROR}{\code{500}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.5.1} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.1}} | 
					
						
							|  |  |  |   \lineiii{NOT_IMPLEMENTED}{\code{501}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.5.2} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.2}} | 
					
						
							|  |  |  |   \lineiii{BAD_GATEWAY}{\code{502}} | 
					
						
							|  |  |  |     {HTTP/1.1 \ulink{RFC 2616, Section 10.5.3} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.3}} | 
					
						
							|  |  |  |   \lineiii{SERVICE_UNAVAILABLE}{\code{503}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.5.4} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.4}} | 
					
						
							|  |  |  |   \lineiii{GATEWAY_TIMEOUT}{\code{504}} | 
					
						
							|  |  |  |     {HTTP/1.1 \ulink{RFC 2616, Section 10.5.5} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.5}} | 
					
						
							|  |  |  |   \lineiii{HTTP_VERSION_NOT_SUPPORTED}{\code{505}} | 
					
						
							|  |  |  |     {HTTP/1.1, \ulink{RFC 2616, Section 10.5.6} | 
					
						
							|  |  |  |       {http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.6}} | 
					
						
							|  |  |  |   \lineiii{INSUFFICIENT_STORAGE}{\code{507}} | 
					
						
							|  |  |  |     {WEBDAV, \ulink{RFC 2518, Section 10.6} | 
					
						
							|  |  |  |       {http://www.webdav.org/specs/rfc2518.htm#STATUS_507}} | 
					
						
							|  |  |  |   \lineiii{NOT_EXTENDED}{\code{510}} | 
					
						
							|  |  |  |     {An HTTP Extension Framework, \rfc{2774}, Section 7} | 
					
						
							|  |  |  | \end{tableiii} | 
					
						
							| 
									
										
										
										
											1995-03-28 13:35:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \subsection{HTTPConnection Objects \label{httpconnection-objects}} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \class{HTTPConnection} instances have the following methods: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{methoddesc}{request}{method, url\optional{, body\optional{, headers}}} | 
					
						
							|  |  |  | This will send a request to the server using the HTTP request method | 
					
						
							|  |  |  | \var{method} and the selector \var{url}.  If the \var{body} argument is | 
					
						
							|  |  |  | present, it should be a string of data to send after the headers are finished. | 
					
						
							|  |  |  | The header Content-Length is automatically set to the correct value. | 
					
						
							|  |  |  | The \var{headers} argument should be a mapping of extra HTTP headers to send | 
					
						
							|  |  |  | with the request. | 
					
						
							|  |  |  | \end{methoddesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{methoddesc}{getresponse}{} | 
					
						
							|  |  |  | Should be called after a request is sent to get the response from the server. | 
					
						
							|  |  |  | Returns an \class{HTTPResponse} instance. | 
					
						
							|  |  |  | \end{methoddesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}{set_debuglevel}{level} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | Set the debugging level (the amount of debugging output printed). | 
					
						
							|  |  |  | The default debug level is \code{0}, meaning no debugging output is | 
					
						
							|  |  |  | printed. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{methoddesc}{connect}{} | 
					
						
							|  |  |  | Connect to the server specified when the object was created. | 
					
						
							|  |  |  | \end{methoddesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{methoddesc}{close}{} | 
					
						
							|  |  |  | Close the connection to the server. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}{send}{data} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | Send data to the server.  This should be used directly only after the | 
					
						
							| 
									
										
										
										
											1998-03-12 05:54:02 +00:00
										 |  |  | \method{endheaders()} method has been called and before | 
					
						
							|  |  |  | \method{getreply()} has been called. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-19 19:51:55 +00:00
										 |  |  | \begin{methoddesc}{putrequest}{request, selector\optional{, | 
					
						
							|  |  |  | skip\_host\optional{, skip_accept_encoding}}} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | This should be the first call after the connection to the server has | 
					
						
							|  |  |  | been made.  It sends a line to the server consisting of the | 
					
						
							|  |  |  | \var{request} string, the \var{selector} string, and the HTTP version | 
					
						
							| 
									
										
										
										
											2003-11-19 19:51:55 +00:00
										 |  |  | (\code{HTTP/1.1}).  To disable automatic sending of \code{Host:} or | 
					
						
							|  |  |  | \code{Accept-Encoding:} headers (for example to accept additional | 
					
						
							|  |  |  | content encodings), specify \var{skip_host} or \var{skip_accept_encoding} | 
					
						
							|  |  |  | with non-False values. | 
					
						
							|  |  |  | \versionchanged[\var{skip_accept_encoding} argument added]{2.4} | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}{putheader}{header, argument\optional{, ...}} | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | Send an \rfc{822}-style header to the server.  It sends a line to the | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | server consisting of the header, a colon and a space, and the first | 
					
						
							|  |  |  | argument.  If more arguments are given, continuation lines are sent, | 
					
						
							|  |  |  | each consisting of a tab and an argument. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}{endheaders}{} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | Send a blank line to the server, signalling the end of the headers. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | \subsection{HTTPResponse Objects \label{httpresponse-objects}} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \class{HTTPResponse} instances have the following methods and attributes: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-09-02 02:32:54 +00:00
										 |  |  | \begin{methoddesc}{read}{\optional{amt}} | 
					
						
							|  |  |  | Reads and returns the response body, or up to the next \var{amt} bytes. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1995-02-27 17:53:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{methoddesc}{getheader}{name\optional{, default}} | 
					
						
							|  |  |  | Get the contents of the header \var{name}, or \var{default} if there is no | 
					
						
							|  |  |  | matching header. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1995-03-17 16:07:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-18 12:46:26 +00:00
										 |  |  | \begin{methoddesc}{getheaders}{} | 
					
						
							|  |  |  | Return a list of (header, value) tuples. \versionadded{2.4} | 
					
						
							|  |  |  | \end{methoddesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | \begin{datadesc}{msg} | 
					
						
							|  |  |  |   A \class{mimetools.Message} instance containing the response headers. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{version} | 
					
						
							|  |  |  |   HTTP protocol version used by server.  10 for HTTP/1.0, 11 for HTTP/1.1. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{status} | 
					
						
							|  |  |  |   Status code returned by server. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{reason} | 
					
						
							|  |  |  |   Reason phrase returned by server. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-25 16:32:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-22 17:42:32 +00:00
										 |  |  | \subsection{Examples \label{httplib-examples}} | 
					
						
							| 
									
										
										
										
											1995-03-17 16:07:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-28 21:51:43 +00:00
										 |  |  | Here is an example session that uses the \samp{GET} method: | 
					
						
							| 
									
										
										
										
											1995-03-17 16:07:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-02-13 06:58:54 +00:00
										 |  |  | \begin{verbatim} | 
					
						
							| 
									
										
										
										
											1995-03-17 16:07:09 +00:00
										 |  |  | >>> import httplib | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | >>> conn = httplib.HTTPConnection("www.python.org") | 
					
						
							|  |  |  | >>> conn.request("GET", "/index.html") | 
					
						
							|  |  |  | >>> r1 = conn.getresponse() | 
					
						
							|  |  |  | >>> print r1.status, r1.reason | 
					
						
							|  |  |  | 200 OK | 
					
						
							|  |  |  | >>> data1 = r1.read() | 
					
						
							|  |  |  | >>> conn.request("GET", "/parrot.spam") | 
					
						
							|  |  |  | >>> r2 = conn.getresponse() | 
					
						
							|  |  |  | >>> print r2.status, r2.reason | 
					
						
							|  |  |  | 404 Not Found | 
					
						
							|  |  |  | >>> data2 = r2.read() | 
					
						
							|  |  |  | >>> conn.close() | 
					
						
							| 
									
										
										
										
											1998-02-13 06:58:54 +00:00
										 |  |  | \end{verbatim} | 
					
						
							| 
									
										
										
										
											2000-06-28 21:51:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Here is an example session that shows how to \samp{POST} requests: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{verbatim} | 
					
						
							|  |  |  | >>> import httplib, urllib | 
					
						
							|  |  |  | >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | >>> headers = {"Content-type": "application/x-www-form-urlencoded", | 
					
						
							|  |  |  | ...            "Accept": "text/plain"} | 
					
						
							|  |  |  | >>> conn = httplib.HTTPConnection("musi-cal.mojam.com:80") | 
					
						
							|  |  |  | >>> conn.request("POST", "/cgi-bin/query", params, headers) | 
					
						
							| 
									
										
										
										
											2001-12-21 03:52:04 +00:00
										 |  |  | >>> response = conn.getresponse() | 
					
						
							| 
									
										
										
										
											2001-11-30 06:06:40 +00:00
										 |  |  | >>> print response.status, response.reason | 
					
						
							|  |  |  | 200 OK | 
					
						
							|  |  |  | >>> data = response.read() | 
					
						
							|  |  |  | >>> conn.close() | 
					
						
							| 
									
										
										
										
											2000-06-28 21:51:43 +00:00
										 |  |  | \end{verbatim} |