• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!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" />
12<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
13<meta name='aesop' content='information' />
14<title>1.1 httplib2 A comprehensive HTTP client library. </title>
15</head>
16<body>
17<div class="navigation">
18<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'
23  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
24<td class='online-navigation'><a rel="parent" title="1. Reference"
25  href="node2.html"><img src='up.png'
26  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"
28  href="http-objects.html"><img src='next.png'
29  border='0' height='32'  alt='Next Page' width='32' /></a></td>
30<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'
33  border='0' height='32'  alt='Contents' width='32' /></a></td>
34<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>
41<a class="sectref" rel="prev" href="node2.html">1. Reference</a>
42<b class="navlabel">Up:</b>
43<a class="sectref" rel="parent" href="node2.html">1. Reference</a>
44<b class="navlabel">Next:</b>
45<a class="sectref" rel="next" href="http-objects.html">1.1.1 Http Objects</a>
46</div>
47<hr /></div>
48</div>
49<!--End of Navigation Panel-->
50
51<h1><a name="SECTION002100000000000000000">
521.1 <tt class="module">httplib2</tt>
53         A comprehensive HTTP client library.  </a>
54</h1>
55
56<p>
57<a name="module-httplib2"></a>
58<p>
59
60<p>
61
62<p>
63The <tt class="module">httplib2</tt> module is a comprehensive HTTP client library with the following features:
64
65<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.
75
76<ul>
77<li>Digest
78</li>
79<li>Basic
80</li>
81<li>WSSE
82
83</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>Proxies</strong></dt>
99<dd>If the Socksipy module is installed then httplib2 can handle sock4, sock5 and http proxies.
100</dd>
101<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>
105
106<p>
107The <tt class="module">httplib2</tt> module defines the following variables:
108
109<p>
110<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
115<p>
116The <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>
120
121<p>
122<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
127<p>
128<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
134<p>
135<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
140<p>
141<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
146<p>
147<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
152<p>
153<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-8' xml:id='l2h-8' class="exception">FailedToDecompressContent</tt></b></dt>
154<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
159<p>
160<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-9' xml:id='l2h-9' class="exception">UnimplementedDigestAuthOptionError</tt></b></dt>
161<dd>
162The server requested a type of Digest authentication that we
163are unfamiliar with.
164</dd></dl>
165
166<p>
167<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-10' xml:id='l2h-10' class="exception">UnimplementedHmacDigestAuthOptionError</tt></b></dt>
168<dd>
169The server requested a type of HMACDigest authentication that we
170are unfamiliar with.
171</dd></dl>
172
173<p>
174<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
175  <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-11' xml:id='l2h-11' class="class">Http</tt></b>(</nobr></td>
176  <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>
177<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.
182The <var>timeout</var> parameter is the socket level timeout.
183The <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.
186</dl>
187
188<p>
189<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
190  <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-12' xml:id='l2h-12' class="class">Response</tt></b>(</nobr></td>
191  <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
199<p>
200<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
201  <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-13' xml:id='l2h-13' class="class">FileCache</tt></b>(</nobr></td>
202  <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
214<p>
215<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>
227
228<p><br /></p><hr class='online-navigation' />
229<div class='online-navigation'>
230<!--Table of Child-Links-->
231<a name="CHILD_LINKS"><strong>Subsections</strong></a>
232
233<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>
238</ul>
239<!--End of Table of Child-Links-->
240</div>
241
242<div class="navigation">
243<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'
249  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
250<td class='online-navigation'><a rel="parent" title="1. Reference"
251  href="node2.html"><img src='up.png'
252  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"
254  href="http-objects.html"><img src='next.png'
255  border='0' height='32'  alt='Next Page' width='32' /></a></td>
256<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'
259  border='0' height='32'  alt='Contents' width='32' /></a></td>
260<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>
267<a class="sectref" rel="prev" href="node2.html">1. Reference</a>
268<b class="navlabel">Up:</b>
269<a class="sectref" rel="parent" href="node2.html">1. Reference</a>
270<b class="navlabel">Next:</b>
271<a class="sectref" rel="next" href="http-objects.html">1.1.1 Http Objects</a>
272</div>
273</div>
274<hr />
275<span class="release-info">Release 0.3, documentation updated on Mar 8, 2007.</span>
276</div>
277<!--End of Navigation Panel-->
278
279</body>
280</html>
281