blob: 4def8526b53d82e10539c3403d4a2afa74d54811 [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">
jcgregoriocde4f092007-03-08 21:59:04 +000063 <td><nobr><b><tt id='l2h-14' xml:id='l2h-14' class="method">request</tt></b>(</nobr></td>
jcgregorio26c0cd72006-07-03 17:36:17 +000064 <td><var>uri, </var><big>[</big><var>method="GET", body=None, headers=None, redirections=DEFAULT_MAX_REDIRECTS</var><big>]</big><var></var>)</td></tr></table></dt>
65<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>
jcgregorio26c0cd72006-07-03 17:36:17 +000085The return value is a tuple of (response, content), the first being and instance of the
86<tt class="class">Response</tt> class, the second being a string that contains the response entity body.
87</dl>
88
jcgregorio88ada9a2007-05-03 13:20:38 +000089<p>
jcgregorio26c0cd72006-07-03 17:36:17 +000090<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
jcgregoriocde4f092007-03-08 21:59:04 +000091 <td><nobr><b><tt id='l2h-15' xml:id='l2h-15' class="method">add_credentials</tt></b>(</nobr></td>
jcgregorio87eee732007-03-09 03:23:11 +000092 <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 +000093<dd>
94Adds a name and password that will be used when a request
jcgregorio87eee732007-03-09 03:23:11 +000095requires authentication. Supplying the optional <var>domain</var> name will
96restrict these credentials to only be sent to the specified
97domain. If <var>domain</var> is not specified then the given credentials will
98be used to try to satisfy every HTTP 401 challenge.
jcgregorio26c0cd72006-07-03 17:36:17 +000099</dl>
100
jcgregorio88ada9a2007-05-03 13:20:38 +0000101<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000102<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
jcgregorio87eee732007-03-09 03:23:11 +0000103 <td><nobr><b><tt id='l2h-16' xml:id='l2h-16' class="method">add_certificate</tt></b>(</nobr></td>
104 <td><var>key, cert, domain</var>)</td></tr></table></dt>
105<dd>
106Add a <var>key</var> and <var>cert</var> that will be used for an SSL connection
107to the specified domain. <var>keyfile</var> is the name of a PEM formatted
108file that contains your private key. <var>certfile</var> is a PEM formatted certificate chain file.
109</dl>
110
jcgregorio88ada9a2007-05-03 13:20:38 +0000111<p>
jcgregorio87eee732007-03-09 03:23:11 +0000112<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
113 <td><nobr><b><tt id='l2h-17' xml:id='l2h-17' class="method">clear_credentials</tt></b>(</nobr></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000114 <td><var></var>)</td></tr></table></dt>
115<dd>
116Remove all the names and passwords used for authentication.
117</dl>
118
jcgregorio88ada9a2007-05-03 13:20:38 +0000119<p>
120<dl><dt><b><tt id='l2h-18' xml:id='l2h-18' class="member">follow_redirects</tt></b></dt>
121<dd>
122If <code>True</code>, which is the default, safe redirects are followed, where
123safe means that the client is only doing a <code>GET</code> or <code>HEAD</code> on the
124URI to which it is being redirected. If <code>False</code> then no redirects are followed.
125Note that a False 'follow_redirects' takes precedence over a True 'follow_all_redirects'.
126Another way of saying that is for 'follow_all_redirects' to have any affect, 'follow_redirects'
jcgregorio5dc440b2007-05-03 13:23:27 +0000127must be True.
jcgregorio88ada9a2007-05-03 13:20:38 +0000128</dl>
129
130<p>
131<dl><dt><b><tt id='l2h-19' xml:id='l2h-19' class="member">follow_all_redirects</tt></b></dt>
jcgregorio26c0cd72006-07-03 17:36:17 +0000132<dd>
jcgregoriof76c9512006-11-07 18:01:50 +0000133If <code>False</code>, which is the default, only safe redirects are followed, where
jcgregorio26c0cd72006-07-03 17:36:17 +0000134safe means that the client is only doing a <code>GET</code> or <code>HEAD</code> on the
jcgregoriof76c9512006-11-07 18:01:50 +0000135URI to which it is being redirected. If <code>True</code> then all redirects are followed.
jcgregorio5dc440b2007-05-03 13:23:27 +0000136Note that a False 'follow_redirects' takes precedence over a True 'follow_all_redirects'.
137Another way of saying that is for 'follow_all_redirects' to have any affect, 'follow_redirects'
138must be True.
jcgregoriof76c9512006-11-07 18:01:50 +0000139</dl>
140
jcgregorio88ada9a2007-05-03 13:20:38 +0000141<p>
142<dl><dt><b><tt id='l2h-20' xml:id='l2h-20' class="member">force_exception_to_status_code</tt></b></dt>
jcgregoriocde4f092007-03-08 21:59:04 +0000143<dd>
144If <code>True</code>, which is the default, then no <tt class="module">httplib2</tt> exceptions will be thrown. Instead,
145those error conditions will be turned into <tt class="class">Response</tt> objects
146that will be returned normally.
147
jcgregorio88ada9a2007-05-03 13:20:38 +0000148<p>
jcgregoriocde4f092007-03-08 21:59:04 +0000149If <code>False</code>, then exceptions will be thrown.
150</dl>
151
jcgregorio88ada9a2007-05-03 13:20:38 +0000152<p>
153<dl><dt><b><tt id='l2h-21' xml:id='l2h-21' class="member">ignore_etag</tt></b></dt>
jcgregoriof76c9512006-11-07 18:01:50 +0000154<dd>
jcgregorio87eee732007-03-09 03:23:11 +0000155Defaults to <code>False</code>. If <code>True</code>, then any etags present in the cached response
156are ignored when processing the current request, i.e. httplib2 does <strong>not</strong> use
jcgregoriof76c9512006-11-07 18:01:50 +0000157'if-match' for PUT or 'if-none-match' when GET or HEAD requests are made. This
158is mainly to deal with broken servers which supply an etag, but change it capriciously.
jcgregorio26c0cd72006-07-03 17:36:17 +0000159</dl>
160
jcgregorio88ada9a2007-05-03 13:20:38 +0000161<p>
jcgregorio26c0cd72006-07-03 17:36:17 +0000162
jcgregorio88ada9a2007-05-03 13:20:38 +0000163<div class="navigation">
jcgregorio26c0cd72006-07-03 17:36:17 +0000164<div class='online-navigation'>
165<p></p><hr />
166<table align="center" width="100%" cellpadding="0" cellspacing="2">
167<tr>
168<td class='online-navigation'><a rel="prev" title="1.1 httplib2 A comprehensive"
169 href="module-httplib2.html"><img src='previous.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000170 border='0' height='32' alt='Previous Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000171<td class='online-navigation'><a rel="parent" title="1.1 httplib2 A comprehensive"
172 href="module-httplib2.html"><img src='up.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000173 border='0' height='32' alt='Up one Level' width='32' /></a></td>
174<td class='online-navigation'><a rel="next" title="1.1.2 cache Objects"
jcgregorio26c0cd72006-07-03 17:36:17 +0000175 href="cache-objects.html"><img src='next.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000176 border='0' height='32' alt='Next Page' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000177<td align="center" width="100%">The httplib2 Library</td>
178<td class='online-navigation'><a rel="contents" title="Table of Contents"
179 href="contents.html"><img src='contents.png'
jcgregorio88ada9a2007-05-03 13:20:38 +0000180 border='0' height='32' alt='Contents' width='32' /></a></td>
jcgregorio26c0cd72006-07-03 17:36:17 +0000181<td class='online-navigation'><img src='blank.png'
182 border='0' height='32' alt='' width='32' /></td>
183<td class='online-navigation'><img src='blank.png'
184 border='0' height='32' alt='' width='32' /></td>
185</tr></table>
186<div class='online-navigation'>
187<b class="navlabel">Previous:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000188<a class="sectref" rel="prev" href="module-httplib2.html">1.1 httplib2 A comprehensive</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000189<b class="navlabel">Up:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000190<a class="sectref" rel="parent" href="module-httplib2.html">1.1 httplib2 A comprehensive</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000191<b class="navlabel">Next:</b>
jcgregorio88ada9a2007-05-03 13:20:38 +0000192<a class="sectref" rel="next" href="cache-objects.html">1.1.2 Cache Objects</a>
jcgregorio26c0cd72006-07-03 17:36:17 +0000193</div>
194</div>
195<hr />
jcgregoriocde4f092007-03-08 21:59:04 +0000196<span class="release-info">Release 0.3, documentation updated on Mar 8, 2007.</span>
jcgregorio88ada9a2007-05-03 13:20:38 +0000197</div>
jcgregorio26c0cd72006-07-03 17:36:17 +0000198<!--End of Navigation Panel-->
199
jcgregorio88ada9a2007-05-03 13:20:38 +0000200</body>
201</html>