1<?xml version="1.0" encoding="ascii"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 3 "DTD/xhtml1-transitional.dtd"> 4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 5<head> 6 <title>googleapiclient.http.HttpRequest</title> 7 <link rel="stylesheet" href="epydoc.css" type="text/css" /> 8 <script type="text/javascript" src="epydoc.js"></script> 9</head> 10 11<body bgcolor="white" text="black" link="blue" vlink="#204080" 12 alink="#204080"> 13<!-- ==================== NAVIGATION BAR ==================== --> 14<table class="navbar" border="0" width="100%" cellpadding="0" 15 bgcolor="#a0c0ff" cellspacing="0"> 16 <tr valign="middle"> 17 <!-- Home link --> 18 <th> <a 19 href="googleapiclient-module.html">Home</a> </th> 20 21 <!-- Tree link --> 22 <th> <a 23 href="module-tree.html">Trees</a> </th> 24 25 <!-- Index link --> 26 <th> <a 27 href="identifier-index.html">Indices</a> </th> 28 29 <!-- Help link --> 30 <th> <a 31 href="help.html">Help</a> </th> 32 33 <th class="navbar" width="100%"></th> 34 </tr> 35</table> 36<table width="100%" cellpadding="0" cellspacing="0"> 37 <tr valign="top"> 38 <td width="100%"> 39 <span class="breadcrumbs"> 40 <a href="googleapiclient-module.html">Package googleapiclient</a> :: 41 <a href="googleapiclient.http-module.html">Module http</a> :: 42 Class HttpRequest 43 </span> 44 </td> 45 <td> 46 <table cellpadding="0" cellspacing="0"> 47 <!-- hide/show private --> 48 <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink" 49 onclick="toggle_private();">hide private</a>]</span></td></tr> 50 <tr><td align="right"><span class="options" 51 >[<a href="frames.html" target="_top">frames</a 52 >] | <a href="googleapiclient.http.HttpRequest-class.html" 53 target="_top">no frames</a>]</span></td></tr> 54 </table> 55 </td> 56 </tr> 57</table> 58<!-- ==================== CLASS DESCRIPTION ==================== --> 59<h1 class="epydoc">Class HttpRequest</h1><p class="nomargin-top"><span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest">source code</a></span></p> 60<center> 61<center> <map id="uml_class_diagram_for_googleap_27" name="uml_class_diagram_for_googleap_27"> 62<area shape="rect" id="node1_6" href="googleapiclient.http.HttpRequest-class.html#__init__" title="Constructor for an HttpRequest." alt="" coords="17,38,676,58"/> 63<area shape="rect" id="node1_7" href="googleapiclient.http.HttpRequest-class.html#execute" title="Execute the request." alt="" coords="17,58,676,78"/> 64<area shape="rect" id="node1_8" href="googleapiclient.http.HttpRequest-class.html#add_response_callback" title="add_response_headers_callback" alt="" coords="17,78,676,98"/> 65<area shape="rect" id="node1_9" href="googleapiclient.http.HttpRequest-class.html#next_chunk" title="Execute the next step of a resumable upload." alt="" coords="17,98,676,118"/> 66<area shape="rect" id="node1_10" href="googleapiclient.http.HttpRequest-class.html#to_json" title="Returns a JSON representation of the HttpRequest." alt="" coords="17,118,676,138"/> 67<area shape="rect" id="node1_11" href="googleapiclient.http.HttpRequest-class.html#from_json" title="Returns an HttpRequest populated with info from a JSON object." alt="" coords="17,138,676,158"/> 68<area shape="rect" id="node1" href="googleapiclient.http.HttpRequest-class.html" title="Encapsulates a single HTTP request." alt="" coords="5,5,688,164"/> 69</map> 70 <img src="uml_class_diagram_for_googleap_27.gif" alt='' usemap="#uml_class_diagram_for_googleap_27" ismap="ismap" class="graph-without-title" /> 71</center> 72</center> 73<hr /> 74<pre class="literalblock"> 75Encapsulates a single HTTP request. 76 77</pre> 78 79<!-- ==================== INSTANCE METHODS ==================== --> 80<a name="section-InstanceMethods"></a> 81<table class="summary" border="1" cellpadding="3" 82 cellspacing="0" width="100%" bgcolor="white"> 83<tr bgcolor="#70b0f0" class="table-header"> 84 <td colspan="2" class="table-header"> 85 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 86 <tr valign="top"> 87 <td align="left"><span class="table-header">Instance Methods</span></td> 88 <td align="right" valign="top" 89 ><span class="options">[<a href="#section-InstanceMethods" 90 class="privatelink" onclick="toggle_private();" 91 >hide private</a>]</span></td> 92 </tr> 93 </table> 94 </td> 95</tr> 96<tr> 97 <td width="15%" align="right" valign="top" class="summary"> 98 <span class="summary-type"> </span> 99 </td><td class="summary"> 100 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 101 <tr> 102 <td><span class="summary-sig"><a href="googleapiclient.http.HttpRequest-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>, 103 <span class="summary-sig-arg">http</span>, 104 <span class="summary-sig-arg">postproc</span>, 105 <span class="summary-sig-arg">uri</span>, 106 <span class="summary-sig-arg">method</span>=<span class="summary-sig-default">'GET'</span>, 107 <span class="summary-sig-arg">body</span>=<span class="summary-sig-default">None</span>, 108 <span class="summary-sig-arg">headers</span>=<span class="summary-sig-default">None</span>, 109 <span class="summary-sig-arg">methodId</span>=<span class="summary-sig-default">None</span>, 110 <span class="summary-sig-arg">resumable</span>=<span class="summary-sig-default">None</span>)</span><br /> 111 Constructor for an HttpRequest.</td> 112 <td align="right" valign="top"> 113 <span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.__init__">source code</a></span> 114 115 </td> 116 </tr> 117 </table> 118 119 </td> 120 </tr> 121<tr> 122 <td width="15%" align="right" valign="top" class="summary"> 123 <span class="summary-type"> </span> 124 </td><td class="summary"> 125 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 126 <tr> 127 <td><span class="summary-sig"><a href="googleapiclient.http.HttpRequest-class.html#execute" class="summary-sig-name">execute</a>(<span class="summary-sig-arg">self</span>, 128 <span class="summary-sig-arg">http</span>=<span class="summary-sig-default">None</span>, 129 <span class="summary-sig-arg">num_retries</span>=<span class="summary-sig-default">0</span>)</span><br /> 130 Execute the request.</td> 131 <td align="right" valign="top"> 132 <span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.execute">source code</a></span> 133 134 </td> 135 </tr> 136 </table> 137 138 </td> 139 </tr> 140<tr> 141 <td width="15%" align="right" valign="top" class="summary"> 142 <span class="summary-type"> </span> 143 </td><td class="summary"> 144 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 145 <tr> 146 <td><span class="summary-sig"><a href="googleapiclient.http.HttpRequest-class.html#add_response_callback" class="summary-sig-name">add_response_callback</a>(<span class="summary-sig-arg">self</span>, 147 <span class="summary-sig-arg">cb</span>)</span><br /> 148 add_response_headers_callback</td> 149 <td align="right" valign="top"> 150 <span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.add_response_callback">source code</a></span> 151 152 </td> 153 </tr> 154 </table> 155 156 </td> 157 </tr> 158<tr> 159 <td width="15%" align="right" valign="top" class="summary"> 160 <span class="summary-type"> </span> 161 </td><td class="summary"> 162 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 163 <tr> 164 <td><span class="summary-sig"><a href="googleapiclient.http.HttpRequest-class.html#next_chunk" class="summary-sig-name">next_chunk</a>(<span class="summary-sig-arg">self</span>, 165 <span class="summary-sig-arg">http</span>=<span class="summary-sig-default">None</span>, 166 <span class="summary-sig-arg">num_retries</span>=<span class="summary-sig-default">0</span>)</span><br /> 167 Execute the next step of a resumable upload.</td> 168 <td align="right" valign="top"> 169 <span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.next_chunk">source code</a></span> 170 171 </td> 172 </tr> 173 </table> 174 175 </td> 176 </tr> 177<tr class="private"> 178 <td width="15%" align="right" valign="top" class="summary"> 179 <span class="summary-type"> </span> 180 </td><td class="summary"> 181 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 182 <tr> 183 <td><span class="summary-sig"><a href="googleapiclient.http.HttpRequest-class.html#_process_response" class="summary-sig-name" onclick="show_private();">_process_response</a>(<span class="summary-sig-arg">self</span>, 184 <span class="summary-sig-arg">resp</span>, 185 <span class="summary-sig-arg">content</span>)</span><br /> 186 Process the response from a single chunk upload.</td> 187 <td align="right" valign="top"> 188 <span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest._process_response">source code</a></span> 189 190 </td> 191 </tr> 192 </table> 193 194 </td> 195 </tr> 196<tr> 197 <td width="15%" align="right" valign="top" class="summary"> 198 <span class="summary-type"> </span> 199 </td><td class="summary"> 200 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 201 <tr> 202 <td><span class="summary-sig"><a name="to_json"></a><span class="summary-sig-name">to_json</span>(<span class="summary-sig-arg">self</span>)</span><br /> 203 Returns a JSON representation of the HttpRequest.</td> 204 <td align="right" valign="top"> 205 <span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.to_json">source code</a></span> 206 207 </td> 208 </tr> 209 </table> 210 211 </td> 212 </tr> 213 <tr> 214 <td colspan="2" class="summary"> 215 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>: 216 <code>__delattr__</code>, 217 <code>__format__</code>, 218 <code>__getattribute__</code>, 219 <code>__hash__</code>, 220 <code>__new__</code>, 221 <code>__reduce__</code>, 222 <code>__reduce_ex__</code>, 223 <code>__repr__</code>, 224 <code>__setattr__</code>, 225 <code>__sizeof__</code>, 226 <code>__str__</code>, 227 <code>__subclasshook__</code> 228 </p> 229 </td> 230 </tr> 231</table> 232<!-- ==================== STATIC METHODS ==================== --> 233<a name="section-StaticMethods"></a> 234<table class="summary" border="1" cellpadding="3" 235 cellspacing="0" width="100%" bgcolor="white"> 236<tr bgcolor="#70b0f0" class="table-header"> 237 <td colspan="2" class="table-header"> 238 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 239 <tr valign="top"> 240 <td align="left"><span class="table-header">Static Methods</span></td> 241 <td align="right" valign="top" 242 ><span class="options">[<a href="#section-StaticMethods" 243 class="privatelink" onclick="toggle_private();" 244 >hide private</a>]</span></td> 245 </tr> 246 </table> 247 </td> 248</tr> 249<tr> 250 <td width="15%" align="right" valign="top" class="summary"> 251 <span class="summary-type"> </span> 252 </td><td class="summary"> 253 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 254 <tr> 255 <td><span class="summary-sig"><a name="from_json"></a><span class="summary-sig-name">from_json</span>(<span class="summary-sig-arg">s</span>, 256 <span class="summary-sig-arg">http</span>, 257 <span class="summary-sig-arg">postproc</span>)</span><br /> 258 Returns an HttpRequest populated with info from a JSON object.</td> 259 <td align="right" valign="top"> 260 <span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.from_json">source code</a></span> 261 262 </td> 263 </tr> 264 </table> 265 266 </td> 267 </tr> 268</table> 269<!-- ==================== PROPERTIES ==================== --> 270<a name="section-Properties"></a> 271<table class="summary" border="1" cellpadding="3" 272 cellspacing="0" width="100%" bgcolor="white"> 273<tr bgcolor="#70b0f0" class="table-header"> 274 <td colspan="2" class="table-header"> 275 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 276 <tr valign="top"> 277 <td align="left"><span class="table-header">Properties</span></td> 278 <td align="right" valign="top" 279 ><span class="options">[<a href="#section-Properties" 280 class="privatelink" onclick="toggle_private();" 281 >hide private</a>]</span></td> 282 </tr> 283 </table> 284 </td> 285</tr> 286 <tr> 287 <td colspan="2" class="summary"> 288 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>: 289 <code>__class__</code> 290 </p> 291 </td> 292 </tr> 293</table> 294<!-- ==================== METHOD DETAILS ==================== --> 295<a name="section-MethodDetails"></a> 296<table class="details" border="1" cellpadding="3" 297 cellspacing="0" width="100%" bgcolor="white"> 298<tr bgcolor="#70b0f0" class="table-header"> 299 <td colspan="2" class="table-header"> 300 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 301 <tr valign="top"> 302 <td align="left"><span class="table-header">Method Details</span></td> 303 <td align="right" valign="top" 304 ><span class="options">[<a href="#section-MethodDetails" 305 class="privatelink" onclick="toggle_private();" 306 >hide private</a>]</span></td> 307 </tr> 308 </table> 309 </td> 310</tr> 311</table> 312<a name="__init__"></a> 313<div> 314<table class="details" border="1" cellpadding="3" 315 cellspacing="0" width="100%" bgcolor="white"> 316<tr><td> 317 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 318 <tr valign="top"><td> 319 <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>, 320 <span class="sig-arg">http</span>, 321 <span class="sig-arg">postproc</span>, 322 <span class="sig-arg">uri</span>, 323 <span class="sig-arg">method</span>=<span class="sig-default">'GET'</span>, 324 <span class="sig-arg">body</span>=<span class="sig-default">None</span>, 325 <span class="sig-arg">headers</span>=<span class="sig-default">None</span>, 326 <span class="sig-arg">methodId</span>=<span class="sig-default">None</span>, 327 <span class="sig-arg">resumable</span>=<span class="sig-default">None</span>)</span> 328 <br /><em class="fname">(Constructor)</em> 329 </h3> 330 </td><td align="right" valign="top" 331 ><span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.__init__">source code</a></span> 332 </td> 333 </tr></table> 334 335 <pre class="literalblock"> 336Constructor for an HttpRequest. 337 338Args: 339 http: httplib2.Http, the transport object to use to make a request 340 postproc: callable, called on the HTTP response and content to transform 341 it into a data object before returning, or raising an exception 342 on an error. 343 uri: string, the absolute URI to send the request to 344 method: string, the HTTP method to use 345 body: string, the request body of the HTTP request, 346 headers: dict, the HTTP request headers 347 methodId: string, a unique identifier for the API method being called. 348 resumable: MediaUpload, None if this is not a resumbale request. 349 350</pre> 351 <dl class="fields"> 352 <dt>Decorators:</dt> 353 <dd><ul class="nomargin-top"> 354 <li><code>@util.positional(4)</code></li> 355 </ul></dd> 356 <dt>Overrides: 357 object.__init__ 358 </dt> 359 </dl> 360</td></tr></table> 361</div> 362<a name="execute"></a> 363<div> 364<table class="details" border="1" cellpadding="3" 365 cellspacing="0" width="100%" bgcolor="white"> 366<tr><td> 367 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 368 <tr valign="top"><td> 369 <h3 class="epydoc"><span class="sig"><span class="sig-name">execute</span>(<span class="sig-arg">self</span>, 370 <span class="sig-arg">http</span>=<span class="sig-default">None</span>, 371 <span class="sig-arg">num_retries</span>=<span class="sig-default">0</span>)</span> 372 </h3> 373 </td><td align="right" valign="top" 374 ><span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.execute">source code</a></span> 375 </td> 376 </tr></table> 377 378 <pre class="literalblock"> 379Execute the request. 380 381Args: 382 http: httplib2.Http, an http object to be used in place of the 383 one the HttpRequest request object was constructed with. 384 num_retries: Integer, number of times to retry with randomized 385 exponential backoff. If all retries fail, the raised HttpError 386 represents the last request. If zero (default), we attempt the 387 request only once. 388 389Returns: 390 A deserialized object model of the response body as determined 391 by the postproc. 392 393Raises: 394 googleapiclient.errors.HttpError if the response was not a 2xx. 395 httplib2.HttpLib2Error if a transport error has occured. 396 397</pre> 398 <dl class="fields"> 399 <dt>Decorators:</dt> 400 <dd><ul class="nomargin-top"> 401 <li><code>@util.positional(1)</code></li> 402 </ul></dd> 403 </dl> 404</td></tr></table> 405</div> 406<a name="add_response_callback"></a> 407<div> 408<table class="details" border="1" cellpadding="3" 409 cellspacing="0" width="100%" bgcolor="white"> 410<tr><td> 411 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 412 <tr valign="top"><td> 413 <h3 class="epydoc"><span class="sig"><span class="sig-name">add_response_callback</span>(<span class="sig-arg">self</span>, 414 <span class="sig-arg">cb</span>)</span> 415 </h3> 416 </td><td align="right" valign="top" 417 ><span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.add_response_callback">source code</a></span> 418 </td> 419 </tr></table> 420 421 <pre class="literalblock"> 422add_response_headers_callback 423 424Args: 425 cb: Callback to be called on receiving the response headers, of signature: 426 427 def cb(resp): 428 # Where resp is an instance of httplib2.Response 429 430</pre> 431 <dl class="fields"> 432 <dt>Decorators:</dt> 433 <dd><ul class="nomargin-top"> 434 <li><code>@util.positional(2)</code></li> 435 </ul></dd> 436 </dl> 437</td></tr></table> 438</div> 439<a name="next_chunk"></a> 440<div> 441<table class="details" border="1" cellpadding="3" 442 cellspacing="0" width="100%" bgcolor="white"> 443<tr><td> 444 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 445 <tr valign="top"><td> 446 <h3 class="epydoc"><span class="sig"><span class="sig-name">next_chunk</span>(<span class="sig-arg">self</span>, 447 <span class="sig-arg">http</span>=<span class="sig-default">None</span>, 448 <span class="sig-arg">num_retries</span>=<span class="sig-default">0</span>)</span> 449 </h3> 450 </td><td align="right" valign="top" 451 ><span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest.next_chunk">source code</a></span> 452 </td> 453 </tr></table> 454 455 <pre class="literalblock"> 456Execute the next step of a resumable upload. 457 458Can only be used if the method being executed supports media uploads and 459the MediaUpload object passed in was flagged as using resumable upload. 460 461Example: 462 463 media = MediaFileUpload('cow.png', mimetype='image/png', 464 chunksize=1000, resumable=True) 465 request = farm.animals().insert( 466 id='cow', 467 name='cow.png', 468 media_body=media) 469 470 response = None 471 while response is None: 472 status, response = request.next_chunk() 473 if status: 474 print "Upload %d%% complete." % int(status.progress() * 100) 475 476 477Args: 478 http: httplib2.Http, an http object to be used in place of the 479 one the HttpRequest request object was constructed with. 480 num_retries: Integer, number of times to retry with randomized 481 exponential backoff. If all retries fail, the raised HttpError 482 represents the last request. If zero (default), we attempt the 483 request only once. 484 485Returns: 486 (status, body): (ResumableMediaStatus, object) 487 The body will be None until the resumable media is fully uploaded. 488 489Raises: 490 googleapiclient.errors.HttpError if the response was not a 2xx. 491 httplib2.HttpLib2Error if a transport error has occured. 492 493</pre> 494 <dl class="fields"> 495 <dt>Decorators:</dt> 496 <dd><ul class="nomargin-top"> 497 <li><code>@util.positional(1)</code></li> 498 </ul></dd> 499 </dl> 500</td></tr></table> 501</div> 502<a name="_process_response"></a> 503<div class="private"> 504<table class="details" border="1" cellpadding="3" 505 cellspacing="0" width="100%" bgcolor="white"> 506<tr><td> 507 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 508 <tr valign="top"><td> 509 <h3 class="epydoc"><span class="sig"><span class="sig-name">_process_response</span>(<span class="sig-arg">self</span>, 510 <span class="sig-arg">resp</span>, 511 <span class="sig-arg">content</span>)</span> 512 </h3> 513 </td><td align="right" valign="top" 514 ><span class="codelink"><a href="googleapiclient.http-pysrc.html#HttpRequest._process_response">source code</a></span> 515 </td> 516 </tr></table> 517 518 <pre class="literalblock"> 519Process the response from a single chunk upload. 520 521Args: 522 resp: httplib2.Response, the response object. 523 content: string, the content of the response. 524 525Returns: 526 (status, body): (ResumableMediaStatus, object) 527 The body will be None until the resumable media is fully uploaded. 528 529Raises: 530 googleapiclient.errors.HttpError if the response was not a 2xx or a 308. 531 532</pre> 533 <dl class="fields"> 534 </dl> 535</td></tr></table> 536</div> 537<br /> 538<!-- ==================== NAVIGATION BAR ==================== --> 539<table class="navbar" border="0" width="100%" cellpadding="0" 540 bgcolor="#a0c0ff" cellspacing="0"> 541 <tr valign="middle"> 542 <!-- Home link --> 543 <th> <a 544 href="googleapiclient-module.html">Home</a> </th> 545 546 <!-- Tree link --> 547 <th> <a 548 href="module-tree.html">Trees</a> </th> 549 550 <!-- Index link --> 551 <th> <a 552 href="identifier-index.html">Indices</a> </th> 553 554 <!-- Help link --> 555 <th> <a 556 href="help.html">Help</a> </th> 557 558 <th class="navbar" width="100%"></th> 559 </tr> 560</table> 561<table border="0" cellpadding="0" cellspacing="0" width="100%%"> 562 <tr> 563 <td align="left" class="footer"> 564 Generated by Epydoc 3.0.1 on Fri Jun 14 15:57:28 2019 565 </td> 566 <td align="right" class="footer"> 567 <a target="mainFrame" href="http://epydoc.sourceforge.net" 568 >http://epydoc.sourceforge.net</a> 569 </td> 570 </tr> 571</table> 572 573<script type="text/javascript"> 574 <!-- 575 // Private objects are initially displayed (because if 576 // javascript is turned off then we want them to be 577 // visible); but by default, we want to hide them. So hide 578 // them unless we have a cookie that says to show them. 579 checkCookie(); 580 // --> 581</script> 582</body> 583</html> 584