jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="ref.css" type='text/css' /> |
| 5 | <link rel="first" href="ref.html" title='The httplib2 Library' /> |
| 6 | <link rel='contents' href='contents.html' title="Contents" /> |
| 7 | <link rel='last' href='about.html' title='About this document...' /> |
| 8 | <link rel='help' href='about.html' title='About this document...' /> |
| 9 | <link rel="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" /> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 13 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 14 | <meta name='aesop' content='information' /> |
| 15 | <title>1.1.1 Http Objects</title> |
| 16 | </head> |
| 17 | <body> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 18 | <div class="navigation"> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 19 | <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' |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 24 | border='0' height='32' alt='Previous Page' width='32' /></a></td> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 25 | <td class='online-navigation'><a rel="parent" title="1.1 httplib2 A comprehensive" |
| 26 | href="module-httplib2.html"><img src='up.png' |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 27 | 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" |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 29 | href="cache-objects.html"><img src='next.png' |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 30 | border='0' height='32' alt='Next Page' width='32' /></a></td> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 31 | <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' |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 34 | border='0' height='32' alt='Contents' width='32' /></a></td> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 35 | <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> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 42 | <a class="sectref" rel="prev" href="module-httplib2.html">1.1 httplib2 A comprehensive</a> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 43 | <b class="navlabel">Up:</b> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 44 | <a class="sectref" rel="parent" href="module-httplib2.html">1.1 httplib2 A comprehensive</a> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 45 | <b class="navlabel">Next:</b> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 46 | <a class="sectref" rel="next" href="cache-objects.html">1.1.2 Cache Objects</a> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 47 | </div> |
| 48 | <hr /></div> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 49 | </div> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 50 | <!--End of Navigation Panel--> |
| 51 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 52 | <h2><a name="SECTION002110000000000000000"></a> |
| 53 | <a name="http-objects"></a> |
| 54 | <br> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 55 | 1.1.1 Http Objects |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 56 | </h2> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 57 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 58 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 59 | Http objects have the following methods: |
| 60 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 61 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 62 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
joe.gregorio | ab704ef | 2007-10-23 15:26:12 +0000 | [diff] [blame] | 63 | <td><nobr><b><tt id='l2h-15' xml:id='l2h-15' class="method">request</tt></b>(</nobr></td> |
jcgregorio | 1464437 | 2007-07-30 14:13:37 +0000 | [diff] [blame] | 64 | <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> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 65 | <dd> |
| 66 | Performs a single HTTP request. |
| 67 | The <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 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 69 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 70 | The <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 |
| 71 | on the methods allowed. |
| 72 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 73 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 74 | The <var>body</var> is the entity body to be sent with the request. It is a string |
| 75 | object. |
| 76 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 77 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 78 | Any extra headers that are to be sent with the request should be provided in the |
| 79 | <var>headers</var> dictionary. |
| 80 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 81 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 82 | The maximum number of redirect to follow before raising an exception is <var>redirections</var>. The default is 5. |
| 83 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 84 | <p> |
jcgregorio | 1464437 | 2007-07-30 14:13:37 +0000 | [diff] [blame] | 85 | The <var>connection_type</var> is the type of connection object to use. The supplied class |
| 86 | should implement the interface of httplib.HTTPConnection. |
| 87 | |
| 88 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 89 | The 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 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 93 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 94 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
joe.gregorio | ab704ef | 2007-10-23 15:26:12 +0000 | [diff] [blame] | 95 | <td><nobr><b><tt id='l2h-16' xml:id='l2h-16' class="method">add_credentials</tt></b>(</nobr></td> |
jcgregorio | 87eee73 | 2007-03-09 03:23:11 +0000 | [diff] [blame] | 96 | <td><var>name, password, </var><big>[</big><var>domain=None</var><big>]</big><var></var>)</td></tr></table></dt> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 97 | <dd> |
Joe Gregorio | 2676371 | 2013-02-19 15:57:37 -0500 | [diff] [blame] | 98 | Adds a name and password that will be used when a request |
jcgregorio | 87eee73 | 2007-03-09 03:23:11 +0000 | [diff] [blame] | 99 | requires authentication. Supplying the optional <var>domain</var> name will |
| 100 | restrict these credentials to only be sent to the specified |
| 101 | domain. If <var>domain</var> is not specified then the given credentials will |
| 102 | be used to try to satisfy every HTTP 401 challenge. |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 103 | </dl> |
| 104 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 105 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 106 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
joe.gregorio | ab704ef | 2007-10-23 15:26:12 +0000 | [diff] [blame] | 107 | <td><nobr><b><tt id='l2h-17' xml:id='l2h-17' class="method">add_certificate</tt></b>(</nobr></td> |
jcgregorio | 87eee73 | 2007-03-09 03:23:11 +0000 | [diff] [blame] | 108 | <td><var>key, cert, domain</var>)</td></tr></table></dt> |
| 109 | <dd> |
| 110 | Add a <var>key</var> and <var>cert</var> that will be used for an SSL connection |
Joe Gregorio | 2676371 | 2013-02-19 15:57:37 -0500 | [diff] [blame] | 111 | to the specified domain. <var>keyfile</var> is the name of a PEM formatted |
| 112 | file that contains your private key. <var>certfile</var> is a PEM formatted certificate chain file. |
jcgregorio | 87eee73 | 2007-03-09 03:23:11 +0000 | [diff] [blame] | 113 | </dl> |
| 114 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 115 | <p> |
jcgregorio | 87eee73 | 2007-03-09 03:23:11 +0000 | [diff] [blame] | 116 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
joe.gregorio | ab704ef | 2007-10-23 15:26:12 +0000 | [diff] [blame] | 117 | <td><nobr><b><tt id='l2h-18' xml:id='l2h-18' class="method">clear_credentials</tt></b>(</nobr></td> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 118 | <td><var></var>)</td></tr></table></dt> |
| 119 | <dd> |
| 120 | Remove all the names and passwords used for authentication. |
| 121 | </dl> |
| 122 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 123 | <p> |
joe.gregorio | ab704ef | 2007-10-23 15:26:12 +0000 | [diff] [blame] | 124 | <dl><dt><b><tt id='l2h-19' xml:id='l2h-19' class="member">follow_redirects</tt></b></dt> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 125 | <dd> |
| 126 | If <code>True</code>, which is the default, safe redirects are followed, where |
| 127 | safe means that the client is only doing a <code>GET</code> or <code>HEAD</code> on the |
| 128 | URI to which it is being redirected. If <code>False</code> then no redirects are followed. |
| 129 | Note that a False 'follow_redirects' takes precedence over a True 'follow_all_redirects'. |
| 130 | Another way of saying that is for 'follow_all_redirects' to have any affect, 'follow_redirects' |
jcgregorio | 5dc440b | 2007-05-03 13:23:27 +0000 | [diff] [blame] | 131 | must be True. |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 132 | </dl> |
| 133 | |
| 134 | <p> |
joe.gregorio | ab704ef | 2007-10-23 15:26:12 +0000 | [diff] [blame] | 135 | <dl><dt><b><tt id='l2h-20' xml:id='l2h-20' class="member">follow_all_redirects</tt></b></dt> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 136 | <dd> |
jcgregorio | f76c951 | 2006-11-07 18:01:50 +0000 | [diff] [blame] | 137 | If <code>False</code>, which is the default, only safe redirects are followed, where |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 138 | safe means that the client is only doing a <code>GET</code> or <code>HEAD</code> on the |
jcgregorio | f76c951 | 2006-11-07 18:01:50 +0000 | [diff] [blame] | 139 | URI to which it is being redirected. If <code>True</code> then all redirects are followed. |
jcgregorio | 5dc440b | 2007-05-03 13:23:27 +0000 | [diff] [blame] | 140 | Note that a False 'follow_redirects' takes precedence over a True 'follow_all_redirects'. |
| 141 | Another way of saying that is for 'follow_all_redirects' to have any affect, 'follow_redirects' |
| 142 | must be True. |
jcgregorio | f76c951 | 2006-11-07 18:01:50 +0000 | [diff] [blame] | 143 | </dl> |
| 144 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 145 | <p> |
joe.gregorio | ab704ef | 2007-10-23 15:26:12 +0000 | [diff] [blame] | 146 | <dl><dt><b><tt id='l2h-21' xml:id='l2h-21' class="member">force_exception_to_status_code</tt></b></dt> |
jcgregorio | cde4f09 | 2007-03-08 21:59:04 +0000 | [diff] [blame] | 147 | <dd> |
| 148 | If <code>True</code>, which is the default, then no <tt class="module">httplib2</tt> exceptions will be thrown. Instead, |
| 149 | those error conditions will be turned into <tt class="class">Response</tt> objects |
| 150 | that will be returned normally. |
| 151 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 152 | <p> |
jcgregorio | cde4f09 | 2007-03-08 21:59:04 +0000 | [diff] [blame] | 153 | If <code>False</code>, then exceptions will be thrown. |
| 154 | </dl> |
| 155 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 156 | <p> |
joe.gregorio | ab704ef | 2007-10-23 15:26:12 +0000 | [diff] [blame] | 157 | <dl><dt><b><tt id='l2h-22' xml:id='l2h-22' class="member">ignore_etag</tt></b></dt> |
jcgregorio | f76c951 | 2006-11-07 18:01:50 +0000 | [diff] [blame] | 158 | <dd> |
jcgregorio | 87eee73 | 2007-03-09 03:23:11 +0000 | [diff] [blame] | 159 | Defaults to <code>False</code>. If <code>True</code>, then any etags present in the cached response |
| 160 | are ignored when processing the current request, i.e. httplib2 does <strong>not</strong> use |
jcgregorio | f76c951 | 2006-11-07 18:01:50 +0000 | [diff] [blame] | 161 | 'if-match' for PUT or 'if-none-match' when GET or HEAD requests are made. This |
| 162 | is mainly to deal with broken servers which supply an etag, but change it capriciously. |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 163 | </dl> |
| 164 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 165 | <p> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 166 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 167 | <div class="navigation"> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 168 | <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' |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 174 | border='0' height='32' alt='Previous Page' width='32' /></a></td> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 175 | <td class='online-navigation'><a rel="parent" title="1.1 httplib2 A comprehensive" |
| 176 | href="module-httplib2.html"><img src='up.png' |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 177 | 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" |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 179 | href="cache-objects.html"><img src='next.png' |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 180 | border='0' height='32' alt='Next Page' width='32' /></a></td> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 181 | <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' |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 184 | border='0' height='32' alt='Contents' width='32' /></a></td> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 185 | <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> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 192 | <a class="sectref" rel="prev" href="module-httplib2.html">1.1 httplib2 A comprehensive</a> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 193 | <b class="navlabel">Up:</b> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 194 | <a class="sectref" rel="parent" href="module-httplib2.html">1.1 httplib2 A comprehensive</a> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 195 | <b class="navlabel">Next:</b> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 196 | <a class="sectref" rel="next" href="cache-objects.html">1.1.2 Cache Objects</a> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 197 | </div> |
| 198 | </div> |
| 199 | <hr /> |
jcgregorio | cde4f09 | 2007-03-08 21:59:04 +0000 | [diff] [blame] | 200 | <span class="release-info">Release 0.3, documentation updated on Mar 8, 2007.</span> |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 201 | </div> |
jcgregorio | 26c0cd7 | 2006-07-03 17:36:17 +0000 | [diff] [blame] | 202 | <!--End of Navigation Panel--> |
| 203 | |
jcgregorio | 88ada9a | 2007-05-03 13:20:38 +0000 | [diff] [blame] | 204 | </body> |
| 205 | </html> |