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