blob: ce4d93185c57722b38c2a89784b2a12e0495d542 [file] [log] [blame]
jcgregorio26c0cd72006-07-03 17:36:17 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="ref.css" type='text/css' />
5<link rel="first" href="ref.html" title='The httplib2 Library' />
6<link rel='contents' href='contents.html' title="Contents" />
7<link rel='last' href='about.html' title='About this document...' />
8<link rel='help' href='about.html' title='About this document...' />
9<link rel="prev" href="node2.html" />
10<link rel="parent" href="node2.html" />
11<link rel="next" href="http-objects.html" />
jcgregorio88ada9a2007-05-03 13:20:38 +000012<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
jcgregorio26c0cd72006-07-03 17:36:17 +000013<meta name='aesop' content='information' />
14<title>1.1 httplib2 A comprehensive HTTP client library. </title>
15</head>
16<body>
jcgregorio88ada9a2007-05-03 13:20:38 +000017<div class="navigation">
jcgregorio26c0cd72006-07-03 17:36:17 +000018<div id='top-navigation-panel' xml:id='top-navigation-panel'>
19<table align="center" width="100%" cellpadding="0" cellspacing="2">
20<tr>
21<td class='online-navigation'><a rel="prev" title="1. Reference"
22 href="node2.html"><img src='previous.png'
jcgregorio88ada9a2007-05-03 13:20:38 +000023 border='0' height='32' alt='Previous Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +000024<td class='online-navigation'><a rel="parent" title="1. Reference"
25 href="node2.html"><img src='up.png'
jcgregorio88ada9a2007-05-03 13:20:38 +000026 border='0' height='32' alt='Up one Level' width='32' /></a></td>
27<td class='online-navigation'><a rel="next" title="1.1.1 http Objects"
jcgregorio26c0cd72006-07-03 17:36:17 +000028 href="http-objects.html"><img src='next.png'
jcgregorio88ada9a2007-05-03 13:20:38 +000029 border='0' height='32' alt='Next Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +000030<td align="center" width="100%">The httplib2 Library</td>
31<td class='online-navigation'><a rel="contents" title="Table of Contents"
32 href="contents.html"><img src='contents.png'
jcgregorio88ada9a2007-05-03 13:20:38 +000033 border='0' height='32' alt='Contents' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +000034<td class='online-navigation'><img src='blank.png'
35 border='0' height='32' alt='' width='32' /></td>
36<td class='online-navigation'><img src='blank.png'
37 border='0' height='32' alt='' width='32' /></td>
38</tr></table>
39<div class='online-navigation'>
40<b class="navlabel">Previous:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +000041<a class="sectref" rel="prev" href="node2.html">1. Reference</a>
jcgregorio26c0cd72006-07-03 17:36:17 +000042<b class="navlabel">Up:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +000043<a class="sectref" rel="parent" href="node2.html">1. Reference</a>
jcgregorio26c0cd72006-07-03 17:36:17 +000044<b class="navlabel">Next:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +000045<a class="sectref" rel="next" href="http-objects.html">1.1.1 Http Objects</a>
jcgregorio26c0cd72006-07-03 17:36:17 +000046</div>
47<hr /></div>
jcgregorio88ada9a2007-05-03 13:20:38 +000048</div>
jcgregorio26c0cd72006-07-03 17:36:17 +000049<!--End of Navigation Panel-->
50
jcgregorio88ada9a2007-05-03 13:20:38 +000051<h1><a name="SECTION002100000000000000000">
jcgregorio26c0cd72006-07-03 17:36:17 +0000521.1 <tt class="module">httplib2</tt>
jcgregorio88ada9a2007-05-03 13:20:38 +000053 A comprehensive HTTP client library. </a>
54</h1>
jcgregorio26c0cd72006-07-03 17:36:17 +000055
jcgregorio88ada9a2007-05-03 13:20:38 +000056<p>
57<a name="module-httplib2"></a>
58<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000059
jcgregorio88ada9a2007-05-03 13:20:38 +000060<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000061
jcgregorio88ada9a2007-05-03 13:20:38 +000062<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000063The <tt class="module">httplib2</tt> module is a comprehensive HTTP client library with the following features:
64
jcgregorio88ada9a2007-05-03 13:20:38 +000065<p>
66<dl>
67<dt><strong>HTTP and HTTPS</strong></dt>
68<dd>HTTPS support is only available if the socket module was compiled with SSL support.
69</dd>
70<dt><strong>Keep-Alive</strong></dt>
71<dd>Supports HTTP 1.1 Keep-Alive, keeping the socket open and performing multiple requests over the same connection if possible.
72</dd>
73<dt><strong>Authentication</strong></dt>
74<dd>The following three types of HTTP Authentication are supported. These can be used over both HTTP and HTTPS.
jcgregorio26c0cd72006-07-03 17:36:17 +000075
jcgregorio88ada9a2007-05-03 13:20:38 +000076<ul>
77<li>Digest
78</li>
79<li>Basic
80</li>
81<li>WSSE
jcgregorio26c0cd72006-07-03 17:36:17 +000082
jcgregorio88ada9a2007-05-03 13:20:38 +000083</li>
84</ul>
85</dd>
86<dt><strong>Caching</strong></dt>
87<dd>The module can optionally operate with a private cache that understands the Cache-Control: header and uses both the ETag and Last-Modified cache validators.
88</dd>
89<dt><strong>All Methods</strong></dt>
90<dd>The module can handle any HTTP request method, not just GET and POST.
91</dd>
92<dt><strong>Redirects</strong></dt>
93<dd>Automatically follows 3XX redirects on GETs.
94</dd>
95<dt><strong>Compression</strong></dt>
96<dd>Handles both 'deflate' and 'gzip' types of compression.
97</dd>
joe.gregorioab704ef2007-10-23 15:26:12 +000098<dt><strong>Proxies</strong></dt>
99<dd>If the Socksipy module is installed then httplib2 can handle sock4, sock5 and http proxies.
100</dd>
jcgregorio88ada9a2007-05-03 13:20:38 +0000101<dt><strong>Lost update support</strong></dt>
102<dd>Automatically adds back ETags into PUT requests to resources we have already cached. This implements Section 3.2 of Detecting the Lost Update Problem Using Unreserved Checkout
103</dd>
104</dl>
jcgregorio26c0cd72006-07-03 17:36:17 +0000105
jcgregorio88ada9a2007-05-03 13:20:38 +0000106<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000107The <tt class="module">httplib2</tt> module defines the following variables:
108
jcgregorio88ada9a2007-05-03 13:20:38 +0000109<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000110<dl><dt><b><tt id='l2h-2' xml:id='l2h-2'>debuglevel</tt></b></dt>
111<dd>
112The amount of debugging information to print. The default is 0.
113</dd></dl>
114
jcgregorio88ada9a2007-05-03 13:20:38 +0000115<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000116The <tt class="module">httplib2</tt> module may raise the following Exceptions. Note that
117there is an option that turns exceptions into
118normal responses with an HTTP status code indicating
119an error occured. See <tt class="member">Http.force_exception_to_status_code</tt>
jcgregorio26c0cd72006-07-03 17:36:17 +0000120
jcgregorio88ada9a2007-05-03 13:20:38 +0000121<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000122<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-3' xml:id='l2h-3' class="exception">HttpLib2Error</tt></b></dt>
123<dd>
124The Base Exception for all exceptions raised by httplib2.
125</dd></dl>
126
jcgregorio88ada9a2007-05-03 13:20:38 +0000127<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000128<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-4' xml:id='l2h-4' class="exception">RedirectMissingLocation</tt></b></dt>
129<dd>
130A 3xx redirect response code was provided but no Location: header
131was provided to point to the new location.
132</dd></dl>
133
jcgregorio88ada9a2007-05-03 13:20:38 +0000134<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000135<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-5' xml:id='l2h-5' class="exception">RedirectLimit</tt></b></dt>
136<dd>
137The maximum number of redirections was reached without coming to a final URI.
138</dd></dl>
139
jcgregorio88ada9a2007-05-03 13:20:38 +0000140<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000141<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-6' xml:id='l2h-6' class="exception">ServerNotFoundError</tt></b></dt>
142<dd>
143Unable to resolve the host name given.
144</dd></dl>
145
jcgregorio88ada9a2007-05-03 13:20:38 +0000146<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000147<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-7' xml:id='l2h-7' class="exception">RelativeURIError</tt></b></dt>
148<dd>
149A relative, as opposed to an absolute URI, was passed into request().
150</dd></dl>
151
jcgregorio88ada9a2007-05-03 13:20:38 +0000152<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000153<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-8' xml:id='l2h-8' class="exception">FailedToDecompressContent</tt></b></dt>
jcgregorio26c0cd72006-07-03 17:36:17 +0000154<dd>
155The headers claimed that the content of the response was compressed but the
156decompression algorithm applied to the content failed.
157</dd></dl>
158
jcgregorio88ada9a2007-05-03 13:20:38 +0000159<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000160<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-9' xml:id='l2h-9' class="exception">UnimplementedDigestAuthOptionError</tt></b></dt>
jcgregorio26c0cd72006-07-03 17:36:17 +0000161<dd>
162The server requested a type of Digest authentication that we
163are unfamiliar with.
164</dd></dl>
165
jcgregorio88ada9a2007-05-03 13:20:38 +0000166<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000167<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-10' xml:id='l2h-10' class="exception">UnimplementedHmacDigestAuthOptionError</tt></b></dt>
jcgregorio26c0cd72006-07-03 17:36:17 +0000168<dd>
169The server requested a type of HMACDigest authentication that we
170are unfamiliar with.
171</dd></dl>
172
jcgregorio88ada9a2007-05-03 13:20:38 +0000173<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000174<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
jcgregoriocde4f092007-03-08 21:59:04 +0000175 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-11' xml:id='l2h-11' class="class">Http</tt></b>(</nobr></td>
joe.gregorioab704ef2007-10-23 15:26:12 +0000176 <td><var></var><big>[</big><var>cache=None</var><big>]</big><var>, </var><big>[</big><var>timeout=None</var><big>]</big><var>, </var><big>[</big><var>proxy_info=None</var><big>]</big><var></var>)</td></tr></table></dt>
jcgregorio26c0cd72006-07-03 17:36:17 +0000177<dd>
178The class that represents a client HTTP interface.
179The <var>cache</var> parameter is either the name of a directory
180to be used as a flat file cache, or it must an object that
181implements the required caching interface.
jcgregorioafc233d2007-03-09 02:30:04 +0000182The <var>timeout</var> parameter is the socket level timeout.
joe.gregorioab704ef2007-10-23 15:26:12 +0000183The <var>proxy_info</var> is an instance of <tt class="class">ProxyInfo</tt> and is supplied
184if a proxy is to be used. Note that the Socksipy module must be
185installed for proxy support to work.
jcgregorio26c0cd72006-07-03 17:36:17 +0000186</dl>
187
jcgregorio88ada9a2007-05-03 13:20:38 +0000188<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000189<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
jcgregoriocde4f092007-03-08 21:59:04 +0000190 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-12' xml:id='l2h-12' class="class">Response</tt></b>(</nobr></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000191 <td><var>info</var>)</td></tr></table></dt>
192<dd>
193Response is a subclass of <tt class="class">dict</tt> and instances of this
194class are returned from calls
195to Http.request. The <var>info</var> parameter is either
196an <tt class="class">rfc822.Message</tt> or an <tt class="class">httplib.HTTPResponse</tt> object.
197</dl>
198
jcgregorio88ada9a2007-05-03 13:20:38 +0000199<p>
jcgregorioee542cc2006-11-16 04:43:19 +0000200<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
jcgregoriocde4f092007-03-08 21:59:04 +0000201 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-13' xml:id='l2h-13' class="class">FileCache</tt></b>(</nobr></td>
jcgregorioee542cc2006-11-16 04:43:19 +0000202 <td><var>dir_name, </var><big>[</big><var>safe=safename</var><big>]</big><var></var>)</td></tr></table></dt>
203<dd>
204FileCache implements a Cache as a directory of files.
205The <var>dir_name</var> parameter is
206the name of the directory to use. If the directory does
207not exist then FileCache attempts to create the directory.
208The optional <var>safe</var> parameter is a funtion which generates
209the cache filename for each URI. A FileCache object is
210constructed and used for caching when you pass a directory name
211into the constructor of <tt class="class">Http</tt>.
212</dl>
213
jcgregorio88ada9a2007-05-03 13:20:38 +0000214<p>
joe.gregorioab704ef2007-10-23 15:26:12 +0000215<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
216 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-14' xml:id='l2h-14' class="class">ProxyInfo</tt></b>(</nobr></td>
217 <td><var>proxy_type, proxy_host, proxy_port, </var><big>[</big><var>proxy_rdns=None</var><big>]</big><var>, </var><big>[</big><var>proxy_user=None</var><big>]</big><var>, </var><big>[</big><var>proxy_pass=None</var><big>]</big><var></var>)</td></tr></table></dt>
218<dd>
219The parameter <var>proxy_type</var> must be set to one of socks.PROXY_TYPE_XXX
220constants. The <var>proxy_host</var> and <var>proxy_port</var> must be set to the location
221of the proxy. The optional <var>proxy_rdns</var> should be set to True if
222the DNS server on the proxy should be used. The <var>proxy_user</var> and
223<var>proxy_pass</var> are supplied when the proxy is protected by authentication.
224</dl>
225
226<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000227
228<p><br /></p><hr class='online-navigation' />
229<div class='online-navigation'>
230<!--Table of Child-Links-->
jcgregorio88ada9a2007-05-03 13:20:38 +0000231<a name="CHILD_LINKS"><strong>Subsections</strong></a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000232
jcgregorio88ada9a2007-05-03 13:20:38 +0000233<ul class="ChildLinks">
234<li><a href="http-objects.html">1.1.1 Http Objects</a>
235<li><a href="cache-objects.html">1.1.2 Cache Objects</a>
236<li><a href="response-objects.html">1.1.3 Response Objects</a>
237<li><a href="httplib2-example.html">1.1.4 Examples</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000238</ul>
239<!--End of Table of Child-Links-->
240</div>
241
jcgregorio88ada9a2007-05-03 13:20:38 +0000242<div class="navigation">
jcgregorio26c0cd72006-07-03 17:36:17 +0000243<div class='online-navigation'>
244<p></p><hr />
245<table align="center" width="100%" cellpadding="0" cellspacing="2">
246<tr>
247<td class='online-navigation'><a rel="prev" title="1. Reference"
248 href="node2.html"><img src='previous.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000249 border='0' height='32' alt='Previous Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000250<td class='online-navigation'><a rel="parent" title="1. Reference"
251 href="node2.html"><img src='up.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000252 border='0' height='32' alt='Up one Level' width='32' /></a></td>
253<td class='online-navigation'><a rel="next" title="1.1.1 http Objects"
jcgregorio26c0cd72006-07-03 17:36:17 +0000254 href="http-objects.html"><img src='next.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000255 border='0' height='32' alt='Next Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000256<td align="center" width="100%">The httplib2 Library</td>
257<td class='online-navigation'><a rel="contents" title="Table of Contents"
258 href="contents.html"><img src='contents.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000259 border='0' height='32' alt='Contents' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000260<td class='online-navigation'><img src='blank.png'
261 border='0' height='32' alt='' width='32' /></td>
262<td class='online-navigation'><img src='blank.png'
263 border='0' height='32' alt='' width='32' /></td>
264</tr></table>
265<div class='online-navigation'>
266<b class="navlabel">Previous:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000267<a class="sectref" rel="prev" href="node2.html">1. Reference</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000268<b class="navlabel">Up:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000269<a class="sectref" rel="parent" href="node2.html">1. Reference</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000270<b class="navlabel">Next:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000271<a class="sectref" rel="next" href="http-objects.html">1.1.1 Http Objects</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000272</div>
273</div>
274<hr />
jcgregoriocde4f092007-03-08 21:59:04 +0000275<span class="release-info">Release 0.3, documentation updated on Mar 8, 2007.</span>
jcgregorio88ada9a2007-05-03 13:20:38 +0000276</div>
jcgregorio26c0cd72006-07-03 17:36:17 +0000277<!--End of Navigation Panel-->
278
jcgregorio88ada9a2007-05-03 13:20:38 +0000279</body>
280</html>