Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 1 | |
| 2 | |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 3 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 4 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 5 | |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 6 | |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 7 | <html xmlns="http://www.w3.org/1999/xhtml"> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 8 | <head> |
| 9 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 10 | |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 11 | <title>httplib2 A comprehensive HTTP client library. — httplib2 0.4 documentation</title> |
| 12 | |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 13 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
| 14 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 15 | |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 16 | <script type="text/javascript"> |
| 17 | var DOCUMENTATION_OPTIONS = { |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 18 | URL_ROOT: '', |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 19 | VERSION: '0.4', |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 20 | COLLAPSE_INDEX: false, |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 21 | FILE_SUFFIX: '.html', |
| 22 | HAS_SOURCE: true |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 23 | }; |
| 24 | </script> |
| 25 | <script type="text/javascript" src="_static/jquery.js"></script> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 26 | <script type="text/javascript" src="_static/underscore.js"></script> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 27 | <script type="text/javascript" src="_static/doctools.js"></script> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 28 | <link rel="top" title="httplib2 0.4 documentation" href="index.html" /> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 29 | <link rel="prev" title="The httplib2 Library" href="index.html" /> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 30 | </head> |
| 31 | <body> |
| 32 | <div class="related"> |
| 33 | <h3>Navigation</h3> |
| 34 | <ul> |
| 35 | <li class="right" style="margin-right: 10px"> |
| 36 | <a href="genindex.html" title="General Index" |
| 37 | accesskey="I">index</a></li> |
| 38 | <li class="right" > |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 39 | <a href="py-modindex.html" title="Python Module Index" |
| 40 | >modules</a> |</li> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 41 | <li class="right" > |
| 42 | <a href="index.html" title="The httplib2 Library" |
| 43 | accesskey="P">previous</a> |</li> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 44 | <li><a href="index.html">httplib2 0.4 documentation</a> »</li> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 45 | </ul> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 46 | </div> |
| 47 | |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 48 | <div class="document"> |
| 49 | <div class="documentwrapper"> |
| 50 | <div class="bodywrapper"> |
| 51 | <div class="body"> |
| 52 | |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 53 | <div class="section" id="module-httplib2"> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 54 | <span id="httplib2-a-comprehensive-http-client-library"></span><h1><a class="reference internal" href="#module-httplib2" title="httplib2"><tt class="xref py py-mod docutils literal"><span class="pre">httplib2</span></tt></a> A comprehensive HTTP client library.<a class="headerlink" href="#module-httplib2" title="Permalink to this headline">ΒΆ</a></h1> |
| 55 | <p>The <a class="reference internal" href="#module-httplib2" title="httplib2"><tt class="xref py py-mod docutils literal"><span class="pre">httplib2</span></tt></a> module is a comprehensive HTTP client library with the |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 56 | following features:</p> |
| 57 | <dl class="describe"> |
| 58 | <dt> |
| 59 | <tt class="descname">HTTP and HTTPS</tt></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 60 | <dd><p>HTTPS support is only available if the socket module was compiled with SSL |
| 61 | support.</p> |
| 62 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 63 | |
| 64 | <dl class="describe"> |
| 65 | <dt> |
| 66 | <tt class="descname">Keep-Alive</tt></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 67 | <dd><p>Supports HTTP 1.1 Keep-Alive, keeping the socket open and performing multiple |
| 68 | requests over the same connection if possible.</p> |
| 69 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 70 | |
| 71 | <dl class="describe"> |
| 72 | <dt> |
| 73 | <tt class="descname">Authentication</tt></dt> |
| 74 | <dd><p>The following three types of HTTP Authentication are supported. These can be |
| 75 | used over both HTTP and HTTPS.</p> |
| 76 | <blockquote> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 77 | <div><ul class="simple"> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 78 | <li>Digest</li> |
| 79 | <li>Basic</li> |
| 80 | <li>WSSE</li> |
| 81 | </ul> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 82 | </div></blockquote> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 83 | </dd></dl> |
| 84 | |
| 85 | <dl class="describe"> |
| 86 | <dt> |
| 87 | <tt class="descname">Caching</tt></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 88 | <dd><p>The module can optionally operate with a private cache that understands the |
| 89 | Cache-Control: header and uses both the ETag and Last-Modified cache validators.</p> |
| 90 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 91 | |
| 92 | <dl class="describe"> |
| 93 | <dt> |
| 94 | <tt class="descname">All Methods</tt></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 95 | <dd><p>The module can handle any HTTP request method, not just GET and POST.</p> |
| 96 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 97 | |
| 98 | <dl class="describe"> |
| 99 | <dt> |
| 100 | <tt class="descname">Redirects</tt></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 101 | <dd><p>Automatically follows 3XX redirects on GETs.</p> |
| 102 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 103 | |
| 104 | <dl class="describe"> |
| 105 | <dt> |
| 106 | <tt class="descname">Compression</tt></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 107 | <dd><p>Handles both <tt class="docutils literal"><span class="pre">deflate</span></tt> and <tt class="docutils literal"><span class="pre">gzip</span></tt> types of compression.</p> |
| 108 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 109 | |
| 110 | <dl class="describe"> |
| 111 | <dt> |
| 112 | <tt class="descname">Lost update support</tt></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 113 | <dd><p>Automatically adds back ETags into PUT requests to resources we have already |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 114 | cached. This implements Section 3.2 of Detecting the Lost Update Problem Using |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 115 | Unreserved Checkout</p> |
| 116 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 117 | |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 118 | <p>The <a class="reference internal" href="#module-httplib2" title="httplib2"><tt class="xref py py-mod docutils literal"><span class="pre">httplib2</span></tt></a> module defines the following variables:</p> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 119 | <dl class="data"> |
| 120 | <dt id="httplib2.debuglevel"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 121 | <tt class="descclassname">httplib2.</tt><tt class="descname">debuglevel</tt><a class="headerlink" href="#httplib2.debuglevel" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 122 | <dd><p>The amount of debugging information to print. The default is 0.</p> |
| 123 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 124 | |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 125 | <dl class="data"> |
| 126 | <dt id="httplib2.RETRIES"> |
| 127 | <tt class="descclassname">httplib2.</tt><tt class="descname">RETRIES</tt><a class="headerlink" href="#httplib2.RETRIES" title="Permalink to this definition">ΒΆ</a></dt> |
| 128 | <dd><p>A request will be tried ‘RETRIES’ times if it fails at the socket/connection level. |
| 129 | The default is 2.</p> |
| 130 | </dd></dl> |
| 131 | |
| 132 | <p>The <a class="reference internal" href="#module-httplib2" title="httplib2"><tt class="xref py py-mod docutils literal"><span class="pre">httplib2</span></tt></a> module may raise the following Exceptions. Note that there |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 133 | is an option that turns exceptions into normal responses with an HTTP status |
| 134 | code indicating an error occured. See |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 135 | <a class="reference internal" href="#httplib2.Http.force_exception_to_status_code" title="httplib2.Http.force_exception_to_status_code"><tt class="xref py py-attr docutils literal"><span class="pre">Http.force_exception_to_status_code</span></tt></a></p> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 136 | <dl class="exception"> |
| 137 | <dt id="httplib2.HttpLib2Error"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 138 | <em class="property">exception </em><tt class="descclassname">httplib2.</tt><tt class="descname">HttpLib2Error</tt><a class="headerlink" href="#httplib2.HttpLib2Error" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 139 | <dd><p>The Base Exception for all exceptions raised by httplib2.</p> |
| 140 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 141 | |
| 142 | <dl class="exception"> |
| 143 | <dt id="httplib2.RedirectMissingLocation"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 144 | <em class="property">exception </em><tt class="descclassname">httplib2.</tt><tt class="descname">RedirectMissingLocation</tt><a class="headerlink" href="#httplib2.RedirectMissingLocation" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 145 | <dd><p>A 3xx redirect response code was provided but no Location: header was provided |
| 146 | to point to the new location.</p> |
| 147 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 148 | |
| 149 | <dl class="exception"> |
| 150 | <dt id="httplib2.RedirectLimit"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 151 | <em class="property">exception </em><tt class="descclassname">httplib2.</tt><tt class="descname">RedirectLimit</tt><a class="headerlink" href="#httplib2.RedirectLimit" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 152 | <dd><p>The maximum number of redirections was reached without coming to a final URI.</p> |
| 153 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 154 | |
| 155 | <dl class="exception"> |
| 156 | <dt id="httplib2.ServerNotFoundError"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 157 | <em class="property">exception </em><tt class="descclassname">httplib2.</tt><tt class="descname">ServerNotFoundError</tt><a class="headerlink" href="#httplib2.ServerNotFoundError" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 158 | <dd><p>Unable to resolve the host name given.</p> |
| 159 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 160 | |
| 161 | <dl class="exception"> |
| 162 | <dt id="httplib2.RelativeURIError"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 163 | <em class="property">exception </em><tt class="descclassname">httplib2.</tt><tt class="descname">RelativeURIError</tt><a class="headerlink" href="#httplib2.RelativeURIError" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 164 | <dd><p>A relative, as opposed to an absolute URI, was passed into request().</p> |
| 165 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 166 | |
| 167 | <dl class="exception"> |
| 168 | <dt id="httplib2.FailedToDecompressContent"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 169 | <em class="property">exception </em><tt class="descclassname">httplib2.</tt><tt class="descname">FailedToDecompressContent</tt><a class="headerlink" href="#httplib2.FailedToDecompressContent" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 170 | <dd><p>The headers claimed that the content of the response was compressed but the |
| 171 | decompression algorithm applied to the content failed.</p> |
| 172 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 173 | |
| 174 | <dl class="exception"> |
| 175 | <dt id="httplib2.UnimplementedDigestAuthOptionError"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 176 | <em class="property">exception </em><tt class="descclassname">httplib2.</tt><tt class="descname">UnimplementedDigestAuthOptionError</tt><a class="headerlink" href="#httplib2.UnimplementedDigestAuthOptionError" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 177 | <dd><p>The server requested a type of Digest authentication that we are unfamiliar |
| 178 | with.</p> |
| 179 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 180 | |
| 181 | <dl class="exception"> |
| 182 | <dt id="httplib2.UnimplementedHmacDigestAuthOptionError"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 183 | <em class="property">exception </em><tt class="descclassname">httplib2.</tt><tt class="descname">UnimplementedHmacDigestAuthOptionError</tt><a class="headerlink" href="#httplib2.UnimplementedHmacDigestAuthOptionError" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 184 | <dd><p>The server requested a type of HMACDigest authentication that we are unfamiliar |
| 185 | with.</p> |
| 186 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 187 | |
| 188 | <dl class="class"> |
| 189 | <dt id="httplib2.Http"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 190 | <em class="property">class </em><tt class="descclassname">httplib2.</tt><tt class="descname">Http</tt><big>(</big><span class="optional">[</span><em>cache=None</em><span class="optional">]</span><span class="optional">[</span>, <em>timeout=None</em><span class="optional">]</span><span class="optional">[</span>, <em>proxy_info=None</em><span class="optional">]</span><span class="optional">[</span>, <em>ca_certs=None</em><span class="optional">]</span><span class="optional">[</span>, <em>disable_ssl_certificate_validation=False</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#httplib2.Http" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 191 | <dd><p>The class that represents a client HTTP interface. The <em>cache</em> parameter is |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 192 | either the name of a directory to be used as a flat file cache, or it must an |
| 193 | object that implements the required caching interface. The <em>timeout</em> parameter |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 194 | is the socket level timeout. The <em>ca_certs</em> parameter is the filename of the |
| 195 | CA certificates to use. If none is given a default set is used. The |
| 196 | <em>disable_ssl_certificate_validation</em> boolean flag determines if ssl certificate validation |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 197 | is done. The <em>proxy_info</em> parameter is an object of type :class:ProxyInfo.</p> |
| 198 | </dd></dl> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 199 | |
| 200 | <dl class="class"> |
| 201 | <dt id="httplib2.ProxyInfo"> |
| 202 | <em class="property">class </em><tt class="descclassname">httplib2.</tt><tt class="descname">ProxyInfo</tt><big>(</big><em>proxy_type</em>, <em>proxy_host</em>, <em>proxy_port</em><span class="optional">[</span>, <em>proxy_rdns=None</em><span class="optional">]</span><span class="optional">[</span>, <em>proxy_user=None</em><span class="optional">]</span><span class="optional">[</span>, <em>proxy_pass=None</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#httplib2.ProxyInfo" title="Permalink to this definition">ΒΆ</a></dt> |
| 203 | <dd><p>Collect information required to use a proxy. |
| 204 | The parameter proxy_type must be set to one of socks.PROXY_TYPE_XXX |
| 205 | constants. For example:</p> |
| 206 | <p>p = ProxyInfo(proxy_type=socks.PROXY_TYPE_HTTP, proxy_host=’localhost’, proxy_port=8000)</p> |
| 207 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 208 | |
| 209 | <dl class="class"> |
| 210 | <dt id="httplib2.Response"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 211 | <em class="property">class </em><tt class="descclassname">httplib2.</tt><tt class="descname">Response</tt><big>(</big><em>info</em><big>)</big><a class="headerlink" href="#httplib2.Response" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 212 | <dd><p>Response is a subclass of <tt class="xref py py-class docutils literal"><span class="pre">dict</span></tt> and instances of this class are |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 213 | returned from calls to Http.request. The <em>info</em> parameter is either an |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 214 | <tt class="xref py py-class docutils literal"><span class="pre">rfc822.Message</span></tt> or an <tt class="xref py py-class docutils literal"><span class="pre">httplib.HTTPResponse</span></tt> object.</p> |
| 215 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 216 | |
| 217 | <dl class="class"> |
| 218 | <dt id="httplib2.FileCache"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 219 | <em class="property">class </em><tt class="descclassname">httplib2.</tt><tt class="descname">FileCache</tt><big>(</big><em>dir_name</em><span class="optional">[</span>, <em>safe=safename</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#httplib2.FileCache" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 220 | <dd><p>FileCache implements a Cache as a directory of files. The <em>dir_name</em> parameter |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 221 | is the name of the directory to use. If the directory does not exist then |
| 222 | FileCache attempts to create the directory. The optional <em>safe</em> parameter is a |
| 223 | funtion which generates the cache filename for each URI. A FileCache object is |
| 224 | constructed and used for caching when you pass a directory name into the |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 225 | constructor of <a class="reference internal" href="#httplib2.Http" title="httplib2.Http"><tt class="xref py py-class docutils literal"><span class="pre">Http</span></tt></a>.</p> |
| 226 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 227 | |
| 228 | <p>Http objects have the following methods:</p> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 229 | <div class="section" id="http-objects"> |
| 230 | <span id="id1"></span><h2>Http Objects<a class="headerlink" href="#http-objects" title="Permalink to this headline">ΒΆ</a></h2> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 231 | <dl class="method"> |
| 232 | <dt id="httplib2.Http.request"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 233 | <tt class="descclassname">Http.</tt><tt class="descname">request</tt><big>(</big><em>uri</em><span class="optional">[</span>, <em>method="GET"</em>, <em>body=None</em>, <em>headers=None</em>, <em>redirections=DEFAULT_MAX_REDIRECTS</em>, <em>connection_type=None</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#httplib2.Http.request" title="Permalink to this definition">ΒΆ</a></dt> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 234 | <dd><p>Performs a single HTTP request. The <em>uri</em> is the URI of the HTTP resource and |
| 235 | can begin with either <tt class="docutils literal"><span class="pre">http</span></tt> or <tt class="docutils literal"><span class="pre">https</span></tt>. The value of <em>uri</em> must be an |
| 236 | absolute URI.</p> |
| 237 | <p>The <em>method</em> is the HTTP method to perform, such as <tt class="docutils literal"><span class="pre">GET</span></tt>, <tt class="docutils literal"><span class="pre">POST</span></tt>, |
| 238 | <tt class="docutils literal"><span class="pre">DELETE</span></tt>, etc. There is no restriction on the methods allowed.</p> |
| 239 | <p>The <em>body</em> is the entity body to be sent with the request. It is a string |
| 240 | object.</p> |
| 241 | <p>Any extra headers that are to be sent with the request should be provided in the |
| 242 | <em>headers</em> dictionary.</p> |
| 243 | <p>The maximum number of redirect to follow before raising an exception is |
| 244 | <em>redirections</em>. The default is 5.</p> |
| 245 | <p>The <em>connection_type</em> is the type of connection object to use. The supplied |
| 246 | class should implement the interface of httplib.HTTPConnection.</p> |
| 247 | <p>The return value is a tuple of (response, content), the first being and instance |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 248 | of the <a class="reference internal" href="#httplib2.Response" title="httplib2.Response"><tt class="xref py py-class docutils literal"><span class="pre">Response</span></tt></a> class, the second being a string that contains the |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 249 | response entity body.</p> |
| 250 | </dd></dl> |
| 251 | |
| 252 | <dl class="method"> |
| 253 | <dt id="httplib2.Http.add_credentials"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 254 | <tt class="descclassname">Http.</tt><tt class="descname">add_credentials</tt><big>(</big><em>name</em>, <em>password</em><span class="optional">[</span>, <em>domain=None</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#httplib2.Http.add_credentials" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 255 | <dd><p>Adds a name and password that will be used when a request requires |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 256 | authentication. Supplying the optional <em>domain</em> name will restrict these |
| 257 | credentials to only be sent to the specified domain. If <em>domain</em> is not |
| 258 | specified then the given credentials will be used to try to satisfy every HTTP |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 259 | 401 challenge.</p> |
| 260 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 261 | |
| 262 | <dl class="method"> |
| 263 | <dt id="httplib2.Http.add_certificate"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 264 | <tt class="descclassname">Http.</tt><tt class="descname">add_certificate</tt><big>(</big><em>key</em>, <em>cert</em>, <em>domain</em><big>)</big><a class="headerlink" href="#httplib2.Http.add_certificate" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 265 | <dd><p>Add a <em>key</em> and <em>cert</em> that will be used for an SSL connection to the specified |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 266 | domain. <em>keyfile</em> is the name of a PEM formatted file that contains your |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 267 | private key. <em>certfile</em> is a PEM formatted certificate chain file.</p> |
| 268 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 269 | |
| 270 | <dl class="method"> |
| 271 | <dt id="httplib2.Http.clear_credentials"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 272 | <tt class="descclassname">Http.</tt><tt class="descname">clear_credentials</tt><big>(</big><big>)</big><a class="headerlink" href="#httplib2.Http.clear_credentials" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 273 | <dd><p>Remove all the names and passwords used for authentication.</p> |
| 274 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 275 | |
| 276 | <dl class="attribute"> |
| 277 | <dt id="httplib2.Http.follow_redirects"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 278 | <tt class="descclassname">Http.</tt><tt class="descname">follow_redirects</tt><a class="headerlink" href="#httplib2.Http.follow_redirects" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 279 | <dd><p>If <tt class="docutils literal"><span class="pre">True</span></tt>, which is the default, safe redirects are followed, where safe means |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 280 | that the client is only doing a <tt class="docutils literal"><span class="pre">GET</span></tt> or <tt class="docutils literal"><span class="pre">HEAD</span></tt> on the URI to which it is |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 281 | being redirected. If <tt class="docutils literal"><span class="pre">False</span></tt> then no redirects are followed. Note that a False |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 282 | ‘follow_redirects’ takes precedence over a True ‘follow_all_redirects’. Another |
| 283 | way of saying that is for ‘follow_all_redirects’ to have any affect, |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 284 | ‘follow_redirects’ must be True.</p> |
| 285 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 286 | |
| 287 | <dl class="attribute"> |
| 288 | <dt id="httplib2.Http.follow_all_redirects"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 289 | <tt class="descclassname">Http.</tt><tt class="descname">follow_all_redirects</tt><a class="headerlink" href="#httplib2.Http.follow_all_redirects" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 290 | <dd><p>If <tt class="docutils literal"><span class="pre">False</span></tt>, which is the default, only safe redirects are followed, where safe |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 291 | means that the client is only doing a <tt class="docutils literal"><span class="pre">GET</span></tt> or <tt class="docutils literal"><span class="pre">HEAD</span></tt> on the URI to which it |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 292 | is being redirected. If <tt class="docutils literal"><span class="pre">True</span></tt> then all redirects are followed. Note that a |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 293 | False ‘follow_redirects’ takes precedence over a True ‘follow_all_redirects’. |
| 294 | Another way of saying that is for ‘follow_all_redirects’ to have any affect, |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 295 | ‘follow_redirects’ must be True.</p> |
| 296 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 297 | |
| 298 | <dl class="attribute"> |
| 299 | <dt id="httplib2.Http.force_exception_to_status_code"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 300 | <tt class="descclassname">Http.</tt><tt class="descname">force_exception_to_status_code</tt><a class="headerlink" href="#httplib2.Http.force_exception_to_status_code" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 301 | <dd><p>If <tt class="docutils literal"><span class="pre">True</span></tt> then no <a class="reference internal" href="#module-httplib2" title="httplib2"><tt class="xref py py-mod docutils literal"><span class="pre">httplib2</span></tt></a> exceptions will be |
| 302 | thrown. Instead, those error conditions will be turned into <a class="reference internal" href="#httplib2.Response" title="httplib2.Response"><tt class="xref py py-class docutils literal"><span class="pre">Response</span></tt></a> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 303 | objects that will be returned normally.</p> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 304 | <p>If <tt class="docutils literal"><span class="pre">False</span></tt>, which is the default, then exceptions will be thrown.</p> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 305 | </dd></dl> |
| 306 | |
| 307 | <dl class="attribute"> |
joe.gregorio | 700f04d | 2008-09-06 04:46:32 +0000 | [diff] [blame] | 308 | <dt id="httplib2.Http.optimistic_concurrency_methods"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 309 | <tt class="descclassname">Http.</tt><tt class="descname">optimistic_concurrency_methods</tt><a class="headerlink" href="#httplib2.Http.optimistic_concurrency_methods" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 310 | <dd><p>By default a list that only contains “PUT”, this attribute |
joe.gregorio | 700f04d | 2008-09-06 04:46:32 +0000 | [diff] [blame] | 311 | controls which methods will get ‘if-match’ headers attached |
| 312 | to them from cached responses with etags. You can append |
| 313 | new items to this list to add new methods that should |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 314 | get this support, such as “PATCH”.</p> |
| 315 | </dd></dl> |
joe.gregorio | 700f04d | 2008-09-06 04:46:32 +0000 | [diff] [blame] | 316 | |
| 317 | <dl class="attribute"> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 318 | <dt id="httplib2.Http.ignore_etag"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 319 | <tt class="descclassname">Http.</tt><tt class="descname">ignore_etag</tt><a class="headerlink" href="#httplib2.Http.ignore_etag" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 320 | <dd><p>Defaults to <tt class="docutils literal"><span class="pre">False</span></tt>. If <tt class="docutils literal"><span class="pre">True</span></tt>, then any etags present in the cached |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 321 | response are ignored when processing the current request, i.e. httplib2 does |
| 322 | <strong>not</strong> use ‘if-match’ for PUT or ‘if-none-match’ when GET or HEAD requests are |
| 323 | made. This is mainly to deal with broken servers which supply an etag, but |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 324 | change it capriciously.</p> |
| 325 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 326 | |
| 327 | <p>If you wish to supply your own caching implementation then you will need to pass |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 328 | in an object that supports the following methods. Note that the <tt class="xref py py-mod docutils literal"><span class="pre">memcache</span></tt> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 329 | module supports this interface natively.</p> |
| 330 | </div> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 331 | <div class="section" id="cache-objects"> |
| 332 | <span id="id2"></span><h2>Cache Objects<a class="headerlink" href="#cache-objects" title="Permalink to this headline">ΒΆ</a></h2> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 333 | <dl class="method"> |
| 334 | <dt id="httplib2.Cache.get"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 335 | <tt class="descclassname">Cache.</tt><tt class="descname">get</tt><big>(</big><em>key</em><big>)</big><a class="headerlink" href="#httplib2.Cache.get" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 336 | <dd><p>Takes a string <em>key</em> and returns the value as a string.</p> |
| 337 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 338 | |
| 339 | <dl class="method"> |
| 340 | <dt id="httplib2.Cache.set"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 341 | <tt class="descclassname">Cache.</tt><tt class="descname">set</tt><big>(</big><em>key</em>, <em>value</em><big>)</big><a class="headerlink" href="#httplib2.Cache.set" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 342 | <dd><p>Takes a string <em>key</em> and <em>value</em> and stores it in the cache.</p> |
| 343 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 344 | |
| 345 | <dl class="method"> |
| 346 | <dt id="httplib2.Cache.delete"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 347 | <tt class="descclassname">Cache.</tt><tt class="descname">delete</tt><big>(</big><em>key</em><big>)</big><a class="headerlink" href="#httplib2.Cache.delete" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 348 | <dd><p>Deletes the cached value stored at <em>key</em>. The value of <em>key</em> is a string.</p> |
| 349 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 350 | |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 351 | <p>Response objects are derived from <tt class="xref py py-class docutils literal"><span class="pre">dict</span></tt> and map header names (lower case |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 352 | with the trailing colon removed) to header values. In addition to the dict |
| 353 | methods a Response object also has:</p> |
| 354 | </div> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 355 | <div class="section" id="response-objects"> |
| 356 | <span id="id3"></span><h2>Response Objects<a class="headerlink" href="#response-objects" title="Permalink to this headline">ΒΆ</a></h2> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 357 | <dl class="attribute"> |
| 358 | <dt id="httplib2.Response.fromcache"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 359 | <tt class="descclassname">Response.</tt><tt class="descname">fromcache</tt><a class="headerlink" href="#httplib2.Response.fromcache" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 360 | <dd><p>If <tt class="docutils literal"><span class="pre">true</span></tt> the the response was returned from the cache.</p> |
| 361 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 362 | |
| 363 | <dl class="attribute"> |
| 364 | <dt id="httplib2.Response.version"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 365 | <tt class="descclassname">Response.</tt><tt class="descname">version</tt><a class="headerlink" href="#httplib2.Response.version" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 366 | <dd><p>The version of HTTP that the server supports. A value of 11 means ‘1.1’.</p> |
| 367 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 368 | |
| 369 | <dl class="attribute"> |
| 370 | <dt id="httplib2.Response.status"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 371 | <tt class="descclassname">Response.</tt><tt class="descname">status</tt><a class="headerlink" href="#httplib2.Response.status" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 372 | <dd><p>The numerical HTTP status code returned in the response.</p> |
| 373 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 374 | |
| 375 | <dl class="attribute"> |
| 376 | <dt id="httplib2.Response.reason"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 377 | <tt class="descclassname">Response.</tt><tt class="descname">reason</tt><a class="headerlink" href="#httplib2.Response.reason" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 378 | <dd><p>The human readable component of the HTTP response status code.</p> |
| 379 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 380 | |
| 381 | <dl class="attribute"> |
| 382 | <dt id="httplib2.Response.previous"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 383 | <tt class="descclassname">Response.</tt><tt class="descname">previous</tt><a class="headerlink" href="#httplib2.Response.previous" title="Permalink to this definition">ΒΆ</a></dt> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 384 | <dd><p>If redirects are followed then the <a class="reference internal" href="#httplib2.Response" title="httplib2.Response"><tt class="xref py py-class docutils literal"><span class="pre">Response</span></tt></a> object returned is just for |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 385 | the very last HTTP request and <em>previous</em> points to the previous |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 386 | <a class="reference internal" href="#httplib2.Response" title="httplib2.Response"><tt class="xref py py-class docutils literal"><span class="pre">Response</span></tt></a> object. In this manner they form a chain going back through |
| 387 | the responses to the very first response. Will be <tt class="docutils literal"><span class="pre">None</span></tt> if there are no |
| 388 | previous respones.</p> |
| 389 | </dd></dl> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 390 | |
| 391 | <p>The Response object also populates the header <tt class="docutils literal"><span class="pre">content-location</span></tt>, that |
| 392 | contains the URI that was ultimately requested. This is useful if redirects were |
| 393 | encountered, you can determine the ultimate URI that the request was sent to. |
| 394 | All Response objects contain this key value, including <tt class="docutils literal"><span class="pre">previous</span></tt> responses so |
| 395 | you can determine the entire chain of redirects. If |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 396 | <a class="reference internal" href="#httplib2.Http.force_exception_to_status_code" title="httplib2.Http.force_exception_to_status_code"><tt class="xref py py-attr docutils literal"><span class="pre">Http.force_exception_to_status_code</span></tt></a> is <tt class="docutils literal"><span class="pre">True</span></tt> and the number of |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 397 | redirects has exceeded the number of allowed number of redirects then the |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 398 | <a class="reference internal" href="#httplib2.Response" title="httplib2.Response"><tt class="xref py py-class docutils literal"><span class="pre">Response</span></tt></a> object will report the error in the status code, but the |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 399 | complete chain of previous responses will still be in tact.</p> |
| 400 | <p>To do a simple <tt class="docutils literal"><span class="pre">GET</span></tt> request just supply the absolute URI of the resource:</p> |
| 401 | </div> |
| 402 | <div class="section" id="examples"> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 403 | <span id="httplib2-example"></span><h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">ΒΆ</a></h2> |
| 404 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">httplib2</span> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 405 | <span class="n">h</span> <span class="o">=</span> <span class="n">httplib2</span><span class="o">.</span><span class="n">Http</span><span class="p">()</span> |
| 406 | <span class="n">resp</span><span class="p">,</span> <span class="n">content</span> <span class="o">=</span> <span class="n">h</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">"http://bitworking.org/"</span><span class="p">)</span> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 407 | <span class="k">assert</span> <span class="n">resp</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">200</span> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 408 | <span class="k">assert</span> <span class="n">resp</span><span class="p">[</span><span class="s">'content-type'</span><span class="p">]</span> <span class="o">==</span> <span class="s">'text/html'</span> |
| 409 | </pre></div> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 410 | </div> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 411 | <p>Here is more complex example that does a PUT of some text to a resource that |
| 412 | requires authentication. The Http instance also uses a file cache in the |
| 413 | directory <tt class="docutils literal"><span class="pre">.cache</span></tt>.</p> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 414 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">httplib2</span> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 415 | <span class="n">h</span> <span class="o">=</span> <span class="n">httplib2</span><span class="o">.</span><span class="n">Http</span><span class="p">(</span><span class="s">".cache"</span><span class="p">)</span> |
| 416 | <span class="n">h</span><span class="o">.</span><span class="n">add_credentials</span><span class="p">(</span><span class="s">'name'</span><span class="p">,</span> <span class="s">'password'</span><span class="p">)</span> |
| 417 | <span class="n">resp</span><span class="p">,</span> <span class="n">content</span> <span class="o">=</span> <span class="n">h</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">"https://example.org/chap/2"</span><span class="p">,</span> |
| 418 | <span class="s">"PUT"</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="s">"This is text"</span><span class="p">,</span> |
| 419 | <span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="s">'content-type'</span><span class="p">:</span><span class="s">'text/plain'</span><span class="p">}</span> <span class="p">)</span> |
| 420 | </pre></div> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 421 | </div> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 422 | <p>Here is an example that connects to a server that supports the Atom Publishing |
| 423 | Protocol.</p> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 424 | <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">httplib2</span> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 425 | <span class="n">h</span> <span class="o">=</span> <span class="n">httplib2</span><span class="o">.</span><span class="n">Http</span><span class="p">()</span> |
| 426 | <span class="n">h</span><span class="o">.</span><span class="n">add_credentials</span><span class="p">(</span><span class="n">myname</span><span class="p">,</span> <span class="n">mypasswd</span><span class="p">)</span> |
| 427 | <span class="n">h</span><span class="o">.</span><span class="n">follow_all_redirects</span> <span class="o">=</span> <span class="bp">True</span> |
| 428 | <span class="n">headers</span> <span class="o">=</span> <span class="p">{</span><span class="s">'Content-Type'</span><span class="p">:</span> <span class="s">'application/atom+xml'</span><span class="p">}</span> |
| 429 | <span class="n">body</span> <span class="o">=</span> <span class="s">"""<?xml version="1.0" ?></span> |
| 430 | <span class="s"> <entry xmlns="http://www.w3.org/2005/Atom"></span> |
| 431 | <span class="s"> <title>Atom-Powered Robots Run Amok</title></span> |
| 432 | <span class="s"> <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id></span> |
| 433 | <span class="s"> <updated>2003-12-13T18:30:02Z</updated></span> |
| 434 | <span class="s"> <author><name>John Doe</name></author></span> |
| 435 | <span class="s"> <content>Some text.</content></span> |
| 436 | <span class="s"></entry></span> |
| 437 | <span class="s">"""</span> |
| 438 | <span class="n">uri</span> <span class="o">=</span> <span class="s">"http://www.example.com/collection/"</span> |
| 439 | <span class="n">resp</span><span class="p">,</span> <span class="n">content</span> <span class="o">=</span> <span class="n">h</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="n">uri</span><span class="p">,</span> <span class="s">"POST"</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">body</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">)</span> |
| 440 | </pre></div> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 441 | </div> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 442 | <p>Here is an example of providing data to an HTML form processor. In this case we |
| 443 | presume this is a POST form. We need to take our data and format it as |
| 444 | “application/x-www-form-urlencoded” data and use that as a body for a POST |
| 445 | request.</p> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 446 | <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">httplib2</span> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 447 | <span class="gp">>>> </span><span class="kn">import</span> <span class="nn">urllib</span> |
| 448 | <span class="gp">>>> </span><span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s">'name'</span><span class="p">:</span> <span class="s">'fred'</span><span class="p">,</span> <span class="s">'address'</span><span class="p">:</span> <span class="s">'123 shady lane'</span><span class="p">}</span> |
| 449 | <span class="gp">>>> </span><span class="n">body</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlencode</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> |
| 450 | <span class="gp">>>> </span><span class="n">body</span> |
| 451 | <span class="go">'name=fred&address=123+shady+lane'</span> |
| 452 | <span class="gp">>>> </span><span class="n">h</span> <span class="o">=</span> <span class="n">httplib2</span><span class="o">.</span><span class="n">Http</span><span class="p">()</span> |
| 453 | <span class="gp">>>> </span><span class="n">resp</span><span class="p">,</span> <span class="n">content</span> <span class="o">=</span> <span class="n">h</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s">"http://example.com"</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s">"POST"</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">body</span><span class="p">)</span> |
| 454 | </pre></div> |
| 455 | </div> |
| 456 | </div> |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 457 | </div> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 458 | |
| 459 | |
| 460 | </div> |
| 461 | </div> |
| 462 | </div> |
| 463 | <div class="sphinxsidebar"> |
| 464 | <div class="sphinxsidebarwrapper"> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 465 | <h3><a href="index.html">Table Of Contents</a></h3> |
| 466 | <ul> |
| 467 | <li><a class="reference internal" href="#"><tt class="docutils literal"><span class="pre">httplib2</span></tt> A comprehensive HTTP client library.</a><ul> |
| 468 | <li><a class="reference internal" href="#http-objects">Http Objects</a></li> |
| 469 | <li><a class="reference internal" href="#cache-objects">Cache Objects</a></li> |
| 470 | <li><a class="reference internal" href="#response-objects">Response Objects</a></li> |
| 471 | <li><a class="reference internal" href="#examples">Examples</a></li> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 472 | </ul> |
| 473 | </li> |
| 474 | </ul> |
| 475 | |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 476 | <h4>Previous topic</h4> |
| 477 | <p class="topless"><a href="index.html" |
| 478 | title="previous chapter">The httplib2 Library</a></p> |
| 479 | <h3>This Page</h3> |
| 480 | <ul class="this-page-menu"> |
| 481 | <li><a href="_sources/libhttplib2.txt" |
| 482 | rel="nofollow">Show Source</a></li> |
| 483 | </ul> |
| 484 | <div id="searchbox" style="display: none"> |
| 485 | <h3>Quick search</h3> |
| 486 | <form class="search" action="search.html" method="get"> |
| 487 | <input type="text" name="q" /> |
| 488 | <input type="submit" value="Go" /> |
| 489 | <input type="hidden" name="check_keywords" value="yes" /> |
| 490 | <input type="hidden" name="area" value="default" /> |
| 491 | </form> |
| 492 | <p class="searchtip" style="font-size: 90%"> |
| 493 | Enter search terms or a module, class or function name. |
| 494 | </p> |
| 495 | </div> |
| 496 | <script type="text/javascript">$('#searchbox').show(0);</script> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 497 | </div> |
| 498 | </div> |
| 499 | <div class="clearer"></div> |
| 500 | </div> |
| 501 | <div class="related"> |
| 502 | <h3>Navigation</h3> |
| 503 | <ul> |
| 504 | <li class="right" style="margin-right: 10px"> |
| 505 | <a href="genindex.html" title="General Index" |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 506 | >index</a></li> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 507 | <li class="right" > |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 508 | <a href="py-modindex.html" title="Python Module Index" |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 509 | >modules</a> |</li> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 510 | <li class="right" > |
| 511 | <a href="index.html" title="The httplib2 Library" |
Joe Gregorio | 24c916a | 2011-06-13 15:13:11 -0400 | [diff] [blame] | 512 | >previous</a> |</li> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 513 | <li><a href="index.html">httplib2 0.4 documentation</a> »</li> |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 514 | </ul> |
| 515 | </div> |
| 516 | <div class="footer"> |
Joe Gregorio | 3b089c9 | 2012-04-17 12:40:39 -0400 | [diff] [blame^] | 517 | © Copyright 2008, Joe Gregorio. |
| 518 | Last updated on Apr 17, 2012. |
| 519 | Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2. |
joe.gregorio | 258eefb | 2008-09-06 01:30:25 +0000 | [diff] [blame] | 520 | </div> |
| 521 | </body> |
| 522 | </html> |