class documentation
class HttpRequest(object):
Constructor: HttpRequest(http, postproc, uri, method, ...)
Encapsulates a single HTTP request.
| Static Method | from |
Returns an HttpRequest populated with info from a JSON object. |
| Static Method | null |
Undocumented |
| Method | __init__ |
Constructor for an HttpRequest. |
| Method | add |
add_response_headers_callback |
| Method | execute |
Execute the request. |
| Method | next |
Execute the next step of a resumable upload. |
| Method | to |
Returns a JSON representation of the HttpRequest. |
| Instance Variable | body |
Undocumented |
| Instance Variable | body |
Undocumented |
| Instance Variable | headers |
Undocumented |
| Instance Variable | http |
Undocumented |
| Instance Variable | method |
Undocumented |
| Instance Variable | method |
Undocumented |
| Instance Variable | postproc |
Undocumented |
| Instance Variable | response |
Undocumented |
| Instance Variable | resumable |
Undocumented |
| Instance Variable | resumable |
Undocumented |
| Instance Variable | resumable |
Undocumented |
| Instance Variable | uri |
Undocumented |
| Method | _process |
Process the response from a single chunk upload. |
| Instance Variable | _in |
Undocumented |
| Instance Variable | _rand |
Undocumented |
| Instance Variable | _sleep |
Undocumented |
@util.positional( 4)
def __init__(self, http, postproc, uri, method='GET', body=None, headers=None, methodId=None, resumable=None): ¶
def __init__(self, http, postproc, uri, method='GET', body=None, headers=None, methodId=None, resumable=None): ¶
Constructor for an HttpRequest.
| Parameters | |
| http | httplib2.Http, the transport object to use to make a request |
| postproc | callable, called on the HTTP response and content to transform it into a data object before returning, or raising an exception on an error. |
| uri | string, the absolute URI to send the request to |
| method | string, the HTTP method to use |
| body | string, the request body of the HTTP request, |
| headers | dict, the HTTP request headers |
| method | string, a unique identifier for the API method being called. |
| resumable | MediaUpload, None if this is not a resumbale request. |
add_response_headers_callback
| Parameters | |
| cb | Callback to be called on receiving the response headers, of signature: |
def cb:resp | # Where resp is an instance of httplib2.Response |
Execute the request.
| Parameters | |
| http | httplib2.Http, an http object to be used in place of the one the HttpRequest request object was constructed with. |
| num | Integer, number of times to retry with randomized exponential backoff. If all retries fail, the raised HttpError represents the last request. If zero (default), we attempt the request only once. |
| Returns | |
| A deserialized object model of the response body as determined by the postproc. | |
| Raises | |
googleapiclient.errors.HttpError if the response was not a 2xx. | |
httplib2.HttpLib2Error if a transport error has occurred. | |
Execute the next step of a resumable upload.
Can only be used if the method being executed supports media uploads and the MediaUpload object passed in was flagged as using resumable upload.
Example
- media = MediaFileUpload('cow.png', mimetype='image/png',
- chunksize=1000, resumable=True)
- request = farm.animals().insert(
- id='cow', name='cow.png', media_body=media)
response = None while response is None:
status, response = request.next_chunk() if status:
print "Upload %d%% complete." % int(status.progress() * 100)
| Parameters | |
| http | httplib2.Http, an http object to be used in place of the one the HttpRequest request object was constructed with. |
| num | Integer, number of times to retry with randomized exponential backoff. If all retries fail, the raised HttpError represents the last request. If zero (default), we attempt the request only once. |
| Returns | |
(status, body) |
|
| Raises | |
googleapiclient.errors.HttpError if the response was not a 2xx. | |
httplib2.HttpLib2Error if a transport error has occurred. | |
Process the response from a single chunk upload.
| Parameters | |
| resp | httplib2.Response, the response object. |
| content | string, the content of the response. |
| Returns | |
(status, body) |
|
| Raises | |
googleapiclient.errors.HttpError if the response was not a 2xx or a 308. | |