blob: e574ff08c538c8eafbc9dd7792a1711feee5697b [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>
98<dt><strong>Lost update support</strong></dt>
99<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
100</dd>
101</dl>
jcgregorio26c0cd72006-07-03 17:36:17 +0000102
jcgregorio88ada9a2007-05-03 13:20:38 +0000103<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000104The <tt class="module">httplib2</tt> module defines the following variables:
105
jcgregorio88ada9a2007-05-03 13:20:38 +0000106<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000107<dl><dt><b><tt id='l2h-2' xml:id='l2h-2'>debuglevel</tt></b></dt>
108<dd>
109The amount of debugging information to print. The default is 0.
110</dd></dl>
111
jcgregorio88ada9a2007-05-03 13:20:38 +0000112<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000113The <tt class="module">httplib2</tt> module may raise the following Exceptions. Note that
114there is an option that turns exceptions into
115normal responses with an HTTP status code indicating
116an error occured. See <tt class="member">Http.force_exception_to_status_code</tt>
jcgregorio26c0cd72006-07-03 17:36:17 +0000117
jcgregorio88ada9a2007-05-03 13:20:38 +0000118<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000119<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-3' xml:id='l2h-3' class="exception">HttpLib2Error</tt></b></dt>
120<dd>
121The Base Exception for all exceptions raised by httplib2.
122</dd></dl>
123
jcgregorio88ada9a2007-05-03 13:20:38 +0000124<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000125<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-4' xml:id='l2h-4' class="exception">RedirectMissingLocation</tt></b></dt>
126<dd>
127A 3xx redirect response code was provided but no Location: header
128was provided to point to the new location.
129</dd></dl>
130
jcgregorio88ada9a2007-05-03 13:20:38 +0000131<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000132<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-5' xml:id='l2h-5' class="exception">RedirectLimit</tt></b></dt>
133<dd>
134The maximum number of redirections was reached without coming to a final URI.
135</dd></dl>
136
jcgregorio88ada9a2007-05-03 13:20:38 +0000137<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000138<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-6' xml:id='l2h-6' class="exception">ServerNotFoundError</tt></b></dt>
139<dd>
140Unable to resolve the host name given.
141</dd></dl>
142
jcgregorio88ada9a2007-05-03 13:20:38 +0000143<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000144<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-7' xml:id='l2h-7' class="exception">RelativeURIError</tt></b></dt>
145<dd>
146A relative, as opposed to an absolute URI, was passed into request().
147</dd></dl>
148
jcgregorio88ada9a2007-05-03 13:20:38 +0000149<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000150<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 +0000151<dd>
152The headers claimed that the content of the response was compressed but the
153decompression algorithm applied to the content failed.
154</dd></dl>
155
jcgregorio88ada9a2007-05-03 13:20:38 +0000156<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000157<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 +0000158<dd>
159The server requested a type of Digest authentication that we
160are unfamiliar with.
161</dd></dl>
162
jcgregorio88ada9a2007-05-03 13:20:38 +0000163<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000164<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 +0000165<dd>
166The server requested a type of HMACDigest authentication that we
167are unfamiliar with.
168</dd></dl>
169
jcgregorio88ada9a2007-05-03 13:20:38 +0000170<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000171<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
jcgregoriocde4f092007-03-08 21:59:04 +0000172 <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-11' xml:id='l2h-11' class="class">Http</tt></b>(</nobr></td>
jcgregorioafc233d2007-03-09 02:30:04 +0000173 <td><var></var><big>[</big><var>cache=None</var><big>]</big><var>, </var><big>[</big><var>timeout=None</var><big>]</big><var></var>)</td></tr></table></dt>
jcgregorio26c0cd72006-07-03 17:36:17 +0000174<dd>
175The class that represents a client HTTP interface.
176The <var>cache</var> parameter is either the name of a directory
177to be used as a flat file cache, or it must an object that
178implements the required caching interface.
jcgregorioafc233d2007-03-09 02:30:04 +0000179The <var>timeout</var> parameter is the socket level timeout.
jcgregorio26c0cd72006-07-03 17:36:17 +0000180</dl>
181
jcgregorio88ada9a2007-05-03 13:20:38 +0000182<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000183<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
jcgregoriocde4f092007-03-08 21:59:04 +0000184 <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 +0000185 <td><var>info</var>)</td></tr></table></dt>
186<dd>
187Response is a subclass of <tt class="class">dict</tt> and instances of this
188class are returned from calls
189to Http.request. The <var>info</var> parameter is either
190an <tt class="class">rfc822.Message</tt> or an <tt class="class">httplib.HTTPResponse</tt> object.
191</dl>
192
jcgregorio88ada9a2007-05-03 13:20:38 +0000193<p>
jcgregorioee542cc2006-11-16 04:43:19 +0000194<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
jcgregoriocde4f092007-03-08 21:59:04 +0000195 <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 +0000196 <td><var>dir_name, </var><big>[</big><var>safe=safename</var><big>]</big><var></var>)</td></tr></table></dt>
197<dd>
198FileCache implements a Cache as a directory of files.
199The <var>dir_name</var> parameter is
200the name of the directory to use. If the directory does
201not exist then FileCache attempts to create the directory.
202The optional <var>safe</var> parameter is a funtion which generates
203the cache filename for each URI. A FileCache object is
204constructed and used for caching when you pass a directory name
205into the constructor of <tt class="class">Http</tt>.
206</dl>
207
jcgregorio88ada9a2007-05-03 13:20:38 +0000208<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000209
210<p><br /></p><hr class='online-navigation' />
211<div class='online-navigation'>
212<!--Table of Child-Links-->
jcgregorio88ada9a2007-05-03 13:20:38 +0000213<a name="CHILD_LINKS"><strong>Subsections</strong></a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000214
jcgregorio88ada9a2007-05-03 13:20:38 +0000215<ul class="ChildLinks">
216<li><a href="http-objects.html">1.1.1 Http Objects</a>
217<li><a href="cache-objects.html">1.1.2 Cache Objects</a>
218<li><a href="response-objects.html">1.1.3 Response Objects</a>
219<li><a href="httplib2-example.html">1.1.4 Examples</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000220</ul>
221<!--End of Table of Child-Links-->
222</div>
223
jcgregorio88ada9a2007-05-03 13:20:38 +0000224<div class="navigation">
jcgregorio26c0cd72006-07-03 17:36:17 +0000225<div class='online-navigation'>
226<p></p><hr />
227<table align="center" width="100%" cellpadding="0" cellspacing="2">
228<tr>
229<td class='online-navigation'><a rel="prev" title="1. Reference"
230 href="node2.html"><img src='previous.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000231 border='0' height='32' alt='Previous Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000232<td class='online-navigation'><a rel="parent" title="1. Reference"
233 href="node2.html"><img src='up.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000234 border='0' height='32' alt='Up one Level' width='32' /></a></td>
235<td class='online-navigation'><a rel="next" title="1.1.1 http Objects"
jcgregorio26c0cd72006-07-03 17:36:17 +0000236 href="http-objects.html"><img src='next.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000237 border='0' height='32' alt='Next Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000238<td align="center" width="100%">The httplib2 Library</td>
239<td class='online-navigation'><a rel="contents" title="Table of Contents"
240 href="contents.html"><img src='contents.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000241 border='0' height='32' alt='Contents' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000242<td class='online-navigation'><img src='blank.png'
243 border='0' height='32' alt='' width='32' /></td>
244<td class='online-navigation'><img src='blank.png'
245 border='0' height='32' alt='' width='32' /></td>
246</tr></table>
247<div class='online-navigation'>
248<b class="navlabel">Previous:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000249<a class="sectref" rel="prev" href="node2.html">1. Reference</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000250<b class="navlabel">Up:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000251<a class="sectref" rel="parent" href="node2.html">1. Reference</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000252<b class="navlabel">Next:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000253<a class="sectref" rel="next" href="http-objects.html">1.1.1 Http Objects</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000254</div>
255</div>
256<hr />
jcgregoriocde4f092007-03-08 21:59:04 +0000257<span class="release-info">Release 0.3, documentation updated on Mar 8, 2007.</span>
jcgregorio88ada9a2007-05-03 13:20:38 +0000258</div>
jcgregorio26c0cd72006-07-03 17:36:17 +0000259<!--End of Navigation Panel-->
260
jcgregorio88ada9a2007-05-03 13:20:38 +0000261</body>
262</html>