blob: 603e52ad4d05195ab5c9f530f29303db3835ae51 [file] [log] [blame]
jcgregorio26c0cd72006-07-03 17:36:17 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="ref.css" type='text/css' />
5<link rel="first" href="ref.html" title='The httplib2 Library' />
6<link rel='contents' href='contents.html' title="Contents" />
7<link rel='last' href='about.html' title='About this document...' />
8<link rel='help' href='about.html' title='About this document...' />
9<link rel="next" href="cache-objects.html" />
10<link rel="prev" href="module-httplib2.html" />
11<link rel="parent" href="module-httplib2.html" />
12<link rel="next" href="cache-objects.html" />
jcgregorio88ada9a2007-05-03 13:20:38 +000013<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
jcgregorio26c0cd72006-07-03 17:36:17 +000014<meta name='aesop' content='information' />
15<title>1.1.1 Http Objects</title>
16</head>
17<body>
jcgregorio88ada9a2007-05-03 13:20:38 +000018<div class="navigation">
jcgregorio26c0cd72006-07-03 17:36:17 +000019<div id='top-navigation-panel' xml:id='top-navigation-panel'>
20<table align="center" width="100%" cellpadding="0" cellspacing="2">
21<tr>
22<td class='online-navigation'><a rel="prev" title="1.1 httplib2 A comprehensive"
23 href="module-httplib2.html"><img src='previous.png'
jcgregorio88ada9a2007-05-03 13:20:38 +000024 border='0' height='32' alt='Previous Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +000025<td class='online-navigation'><a rel="parent" title="1.1 httplib2 A comprehensive"
26 href="module-httplib2.html"><img src='up.png'
jcgregorio88ada9a2007-05-03 13:20:38 +000027 border='0' height='32' alt='Up one Level' width='32' /></a></td>
28<td class='online-navigation'><a rel="next" title="1.1.2 cache Objects"
jcgregorio26c0cd72006-07-03 17:36:17 +000029 href="cache-objects.html"><img src='next.png'
jcgregorio88ada9a2007-05-03 13:20:38 +000030 border='0' height='32' alt='Next Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +000031<td align="center" width="100%">The httplib2 Library</td>
32<td class='online-navigation'><a rel="contents" title="Table of Contents"
33 href="contents.html"><img src='contents.png'
jcgregorio88ada9a2007-05-03 13:20:38 +000034 border='0' height='32' alt='Contents' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +000035<td class='online-navigation'><img src='blank.png'
36 border='0' height='32' alt='' width='32' /></td>
37<td class='online-navigation'><img src='blank.png'
38 border='0' height='32' alt='' width='32' /></td>
39</tr></table>
40<div class='online-navigation'>
41<b class="navlabel">Previous:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +000042<a class="sectref" rel="prev" href="module-httplib2.html">1.1 httplib2 A comprehensive</a>
jcgregorio26c0cd72006-07-03 17:36:17 +000043<b class="navlabel">Up:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +000044<a class="sectref" rel="parent" href="module-httplib2.html">1.1 httplib2 A comprehensive</a>
jcgregorio26c0cd72006-07-03 17:36:17 +000045<b class="navlabel">Next:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +000046<a class="sectref" rel="next" href="cache-objects.html">1.1.2 Cache Objects</a>
jcgregorio26c0cd72006-07-03 17:36:17 +000047</div>
48<hr /></div>
jcgregorio88ada9a2007-05-03 13:20:38 +000049</div>
jcgregorio26c0cd72006-07-03 17:36:17 +000050<!--End of Navigation Panel-->
51
jcgregorio88ada9a2007-05-03 13:20:38 +000052<h2><a name="SECTION002110000000000000000"></a>
53<a name="http-objects"></a>
54<br>
jcgregorio26c0cd72006-07-03 17:36:17 +0000551.1.1 Http Objects
jcgregorio88ada9a2007-05-03 13:20:38 +000056</h2>
jcgregorio26c0cd72006-07-03 17:36:17 +000057
jcgregorio88ada9a2007-05-03 13:20:38 +000058<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000059Http objects have the following methods:
60
jcgregorio88ada9a2007-05-03 13:20:38 +000061<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000062<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
joe.gregorioab704ef2007-10-23 15:26:12 +000063 <td><nobr><b><tt id='l2h-15' xml:id='l2h-15' class="method">request</tt></b>(</nobr></td>
jcgregorio14644372007-07-30 14:13:37 +000064 <td><var>uri, </var><big>[</big><var>method="GET", body=None, headers=None, redirections=DEFAULT_MAX_REDIRECTS, connection_type=None</var><big>]</big><var></var>)</td></tr></table></dt>
jcgregorio26c0cd72006-07-03 17:36:17 +000065<dd>
66Performs a single HTTP request.
67The <var>uri</var> is the URI of the HTTP resource and can begin with either <code>http</code> or <code>https</code>. The value of <var>uri</var> must be an absolute URI.
68
jcgregorio88ada9a2007-05-03 13:20:38 +000069<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000070The <var>method</var> is the HTTP method to perform, such as <code>GET</code>, <code>POST</code>, <code>DELETE</code>, etc. There is no restriction
71on the methods allowed.
72
jcgregorio88ada9a2007-05-03 13:20:38 +000073<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000074The <var>body</var> is the entity body to be sent with the request. It is a string
75object.
76
jcgregorio88ada9a2007-05-03 13:20:38 +000077<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000078Any extra headers that are to be sent with the request should be provided in the
79<var>headers</var> dictionary.
80
jcgregorio88ada9a2007-05-03 13:20:38 +000081<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000082The maximum number of redirect to follow before raising an exception is <var>redirections</var>. The default is 5.
83
jcgregorio88ada9a2007-05-03 13:20:38 +000084<p>
jcgregorio14644372007-07-30 14:13:37 +000085The <var>connection_type</var> is the type of connection object to use. The supplied class
86should implement the interface of httplib.HTTPConnection.
87
88<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000089The return value is a tuple of (response, content), the first being and instance of the
90<tt class="class">Response</tt> class, the second being a string that contains the response entity body.
91</dl>
92
jcgregorio88ada9a2007-05-03 13:20:38 +000093<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000094<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
joe.gregorioab704ef2007-10-23 15:26:12 +000095 <td><nobr><b><tt id='l2h-16' xml:id='l2h-16' class="method">add_credentials</tt></b>(</nobr></td>
jcgregorio87eee732007-03-09 03:23:11 +000096 <td><var>name, password, </var><big>[</big><var>domain=None</var><big>]</big><var></var>)</td></tr></table></dt>
jcgregorio26c0cd72006-07-03 17:36:17 +000097<dd>
Joe Gregorio26763712013-02-19 15:57:37 -050098Adds a name and password that will be used when a request
jcgregorio87eee732007-03-09 03:23:11 +000099requires authentication. Supplying the optional <var>domain</var> name will
100restrict these credentials to only be sent to the specified
101domain. If <var>domain</var> is not specified then the given credentials will
102be used to try to satisfy every HTTP 401 challenge.
jcgregorio26c0cd72006-07-03 17:36:17 +0000103</dl>
104
jcgregorio88ada9a2007-05-03 13:20:38 +0000105<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000106<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
joe.gregorioab704ef2007-10-23 15:26:12 +0000107 <td><nobr><b><tt id='l2h-17' xml:id='l2h-17' class="method">add_certificate</tt></b>(</nobr></td>
jcgregorio87eee732007-03-09 03:23:11 +0000108 <td><var>key, cert, domain</var>)</td></tr></table></dt>
109<dd>
110Add a <var>key</var> and <var>cert</var> that will be used for an SSL connection
Joe Gregorio26763712013-02-19 15:57:37 -0500111to the specified domain. <var>keyfile</var> is the name of a PEM formatted
112file that contains your private key. <var>certfile</var> is a PEM formatted certificate chain file.
jcgregorio87eee732007-03-09 03:23:11 +0000113</dl>
114
jcgregorio88ada9a2007-05-03 13:20:38 +0000115<p>
jcgregorio87eee732007-03-09 03:23:11 +0000116<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
joe.gregorioab704ef2007-10-23 15:26:12 +0000117 <td><nobr><b><tt id='l2h-18' xml:id='l2h-18' class="method">clear_credentials</tt></b>(</nobr></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000118 <td><var></var>)</td></tr></table></dt>
119<dd>
120Remove all the names and passwords used for authentication.
121</dl>
122
jcgregorio88ada9a2007-05-03 13:20:38 +0000123<p>
joe.gregorioab704ef2007-10-23 15:26:12 +0000124<dl><dt><b><tt id='l2h-19' xml:id='l2h-19' class="member">follow_redirects</tt></b></dt>
jcgregorio88ada9a2007-05-03 13:20:38 +0000125<dd>
126If <code>True</code>, which is the default, safe redirects are followed, where
127safe means that the client is only doing a <code>GET</code> or <code>HEAD</code> on the
128URI to which it is being redirected. If <code>False</code> then no redirects are followed.
129Note that a False 'follow_redirects' takes precedence over a True 'follow_all_redirects'.
130Another way of saying that is for 'follow_all_redirects' to have any affect, 'follow_redirects'
jcgregorio5dc440b2007-05-03 13:23:27 +0000131must be True.
jcgregorio88ada9a2007-05-03 13:20:38 +0000132</dl>
133
134<p>
joe.gregorioab704ef2007-10-23 15:26:12 +0000135<dl><dt><b><tt id='l2h-20' xml:id='l2h-20' class="member">follow_all_redirects</tt></b></dt>
jcgregorio26c0cd72006-07-03 17:36:17 +0000136<dd>
jcgregoriof76c9512006-11-07 18:01:50 +0000137If <code>False</code>, which is the default, only safe redirects are followed, where
jcgregorio26c0cd72006-07-03 17:36:17 +0000138safe means that the client is only doing a <code>GET</code> or <code>HEAD</code> on the
jcgregoriof76c9512006-11-07 18:01:50 +0000139URI to which it is being redirected. If <code>True</code> then all redirects are followed.
jcgregorio5dc440b2007-05-03 13:23:27 +0000140Note that a False 'follow_redirects' takes precedence over a True 'follow_all_redirects'.
141Another way of saying that is for 'follow_all_redirects' to have any affect, 'follow_redirects'
142must be True.
jcgregoriof76c9512006-11-07 18:01:50 +0000143</dl>
144
jcgregorio88ada9a2007-05-03 13:20:38 +0000145<p>
joe.gregorioab704ef2007-10-23 15:26:12 +0000146<dl><dt><b><tt id='l2h-21' xml:id='l2h-21' class="member">force_exception_to_status_code</tt></b></dt>
jcgregoriocde4f092007-03-08 21:59:04 +0000147<dd>
148If <code>True</code>, which is the default, then no <tt class="module">httplib2</tt> exceptions will be thrown. Instead,
149those error conditions will be turned into <tt class="class">Response</tt> objects
150that will be returned normally.
151
jcgregorio88ada9a2007-05-03 13:20:38 +0000152<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000153If <code>False</code>, then exceptions will be thrown.
154</dl>
155
jcgregorio88ada9a2007-05-03 13:20:38 +0000156<p>
joe.gregorioab704ef2007-10-23 15:26:12 +0000157<dl><dt><b><tt id='l2h-22' xml:id='l2h-22' class="member">ignore_etag</tt></b></dt>
jcgregoriof76c9512006-11-07 18:01:50 +0000158<dd>
jcgregorio87eee732007-03-09 03:23:11 +0000159Defaults to <code>False</code>. If <code>True</code>, then any etags present in the cached response
160are ignored when processing the current request, i.e. httplib2 does <strong>not</strong> use
jcgregoriof76c9512006-11-07 18:01:50 +0000161'if-match' for PUT or 'if-none-match' when GET or HEAD requests are made. This
162is mainly to deal with broken servers which supply an etag, but change it capriciously.
jcgregorio26c0cd72006-07-03 17:36:17 +0000163</dl>
164
jcgregorio88ada9a2007-05-03 13:20:38 +0000165<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000166
jcgregorio88ada9a2007-05-03 13:20:38 +0000167<div class="navigation">
jcgregorio26c0cd72006-07-03 17:36:17 +0000168<div class='online-navigation'>
169<p></p><hr />
170<table align="center" width="100%" cellpadding="0" cellspacing="2">
171<tr>
172<td class='online-navigation'><a rel="prev" title="1.1 httplib2 A comprehensive"
173 href="module-httplib2.html"><img src='previous.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000174 border='0' height='32' alt='Previous Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000175<td class='online-navigation'><a rel="parent" title="1.1 httplib2 A comprehensive"
176 href="module-httplib2.html"><img src='up.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000177 border='0' height='32' alt='Up one Level' width='32' /></a></td>
178<td class='online-navigation'><a rel="next" title="1.1.2 cache Objects"
jcgregorio26c0cd72006-07-03 17:36:17 +0000179 href="cache-objects.html"><img src='next.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000180 border='0' height='32' alt='Next Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000181<td align="center" width="100%">The httplib2 Library</td>
182<td class='online-navigation'><a rel="contents" title="Table of Contents"
183 href="contents.html"><img src='contents.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000184 border='0' height='32' alt='Contents' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000185<td class='online-navigation'><img src='blank.png'
186 border='0' height='32' alt='' width='32' /></td>
187<td class='online-navigation'><img src='blank.png'
188 border='0' height='32' alt='' width='32' /></td>
189</tr></table>
190<div class='online-navigation'>
191<b class="navlabel">Previous:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000192<a class="sectref" rel="prev" href="module-httplib2.html">1.1 httplib2 A comprehensive</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000193<b class="navlabel">Up:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000194<a class="sectref" rel="parent" href="module-httplib2.html">1.1 httplib2 A comprehensive</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000195<b class="navlabel">Next:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000196<a class="sectref" rel="next" href="cache-objects.html">1.1.2 Cache Objects</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000197</div>
198</div>
199<hr />
jcgregoriocde4f092007-03-08 21:59:04 +0000200<span class="release-info">Release 0.3, documentation updated on Mar 8, 2007.</span>
jcgregorio88ada9a2007-05-03 13:20:38 +0000201</div>
jcgregorio26c0cd72006-07-03 17:36:17 +0000202<!--End of Navigation Panel-->
203
jcgregorio88ada9a2007-05-03 13:20:38 +0000204</body>
205</html>