Package googleapiclient :: Module http :: Class HttpRequest
[hide private]
[frames] | no frames]

Class HttpRequest

source code


Encapsulates a single HTTP request.

Instance Methods [hide private]
 
__init__(self, http, postproc, uri, method="GET", body=None, headers=None, methodId=None, resumable=None)
Constructor for an HttpRequest.
source code
 
execute(self, http=None, num_retries=0)
Execute the request.
source code
 
add_response_callback(self, cb)
add_response_headers_callback
source code
 
next_chunk(self, http=None, num_retries=0)
Execute the next step of a resumable upload.
source code
 
_process_response(self, resp, content)
Process the response from a single chunk upload.
source code
 
to_json(self)
Returns a JSON representation of the HttpRequest.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
from_json(s, http, postproc)
Returns an HttpRequest populated with info from a JSON object.
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, http, postproc, uri, method="GET", body=None, headers=None, methodId=None, resumable=None)
(Constructor)

source code 
Constructor for an HttpRequest.

Args:
  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
  methodId: string, a unique identifier for the API method being called.
  resumable: MediaUpload, None if this is not a resumbale request.

Decorators:
  • @util.positional(4)
Overrides: object.__init__

execute(self, http=None, num_retries=0)

source code 
Execute the request.

Args:
  http: httplib2.Http, an http object to be used in place of the
        one the HttpRequest request object was constructed with.
  num_retries: 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.

Decorators:
  • @util.positional(1)

add_response_callback(self, cb)

source code 
add_response_headers_callback

Args:
  cb: Callback to be called on receiving the response headers, of signature:

  def cb(resp):
    # Where resp is an instance of httplib2.Response

Decorators:
  • @util.positional(2)

next_chunk(self, http=None, num_retries=0)

source code 
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)


Args:
  http: httplib2.Http, an http object to be used in place of the
        one the HttpRequest request object was constructed with.
  num_retries: 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): (ResumableMediaStatus, object)
     The body will be None until the resumable media is fully uploaded.

Raises:
  googleapiclient.errors.HttpError if the response was not a 2xx.
  httplib2.HttpLib2Error if a transport error has occurred.

Decorators:
  • @util.positional(1)

_process_response(self, resp, content)

source code 
Process the response from a single chunk upload.

Args:
  resp: httplib2.Response, the response object.
  content: string, the content of the response.

Returns:
  (status, body): (ResumableMediaStatus, object)
     The body will be None until the resumable media is fully uploaded.

Raises:
  googleapiclient.errors.HttpError if the response was not a 2xx or a 308.