module documentation

Classes to encapsulate a single HTTP request.

The classes implement a command pattern, with every object supporting an execute() method that does the actual HTTP request.

Class BatchHttpRequest Batches multiple HttpRequest objects into a single HTTP request.
Class HttpMock Mock of httplib2.Http
Class HttpMockSequence Mock of httplib2.Http
Class HttpRequest Encapsulates a single HTTP request.
Class HttpRequestMock Mock of HttpRequest.
Class MediaDownloadProgress Status of a resumable download.
Class MediaFileUpload A MediaUpload for a file.
Class MediaInMemoryUpload MediaUpload for a chunk of bytes.
Class MediaIoBaseDownload "Download media resources.
Class MediaIoBaseUpload A MediaUpload for a io.Base objects.
Class MediaUpload Describes a media object to upload.
Class MediaUploadProgress Status of a resumable upload.
Class RequestMockBuilder A simple mock of HttpRequest
Function build_http Builds httplib2.Http object
Function set_user_agent Set the user-agent on every request.
Function tunnel_patch Tunnel PATCH requests over POST.
Constant DEFAULT_CHUNK_SIZE Undocumented
Constant DEFAULT_HTTP_TIMEOUT_SEC Undocumented
Constant LOGGER Undocumented
Constant MAX_BATCH_LIMIT Undocumented
Constant MAX_URI_LENGTH Undocumented
Variable __author__ Undocumented
Class _StreamSlice Truncated stream.
Function _retry_request Retries an HTTP request multiple times while handling errors.
Function _should_retry_response Determines whether a response should be retried.
Constant _LEGACY_BATCH_URI Undocumented
Constant _TOO_MANY_REQUESTS Undocumented
def build_http():

Builds httplib2.Http object

Returns: A httplib2.Http object, which is used to make http requests, and which has timeout set by default. To override default timeout call

socket.setdefaulttimeout(timeout_in_sec)

before interacting with this method.

def set_user_agent(http, user_agent):

Set the user-agent on every request.

Example

h = httplib2.Http() h = set_user_agent(h, "my-app-name/6.0")

Most of the time the user-agent will be set doing auth, this is for the rare cases where you are accessing an unauthenticated endpoint.

Parameters
httpUndocumented
user_agentstring, the value for the user-agent header.
http - An instance of httplib2.Httpor something that acts like it.
Returns
A modified instance of http that was passed in.
def tunnel_patch(http):

Tunnel PATCH requests over POST.

Example

h = httplib2.Http() h = tunnel_patch(h, "my-app-name/6.0")

Useful if you are running on a platform that doesn't support PATCH. Apply this last if you are using OAuth 1.0, as changing the method will result in a different signature.

Parameters
httpUndocumented
http - An instance of httplib2.Httpor something that acts like it.
Returns
A modified instance of http that was passed in.
DEFAULT_CHUNK_SIZE =

Undocumented

Value
100 * 1024 * 1024
DEFAULT_HTTP_TIMEOUT_SEC: int =

Undocumented

Value
60
LOGGER =

Undocumented

Value
logging.getLogger(__name__)
MAX_BATCH_LIMIT: int =

Undocumented

Value
1000
MAX_URI_LENGTH: int =

Undocumented

Value
2048
__author__: str =

Undocumented

def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args, **kwargs):

Retries an HTTP request multiple times while handling errors.

If after all retries the request still fails, last error is either returned as return value (for HTTP 5xx errors) or thrown (for ssl.SSLError).

Parameters
httpHttp object to be used to execute request.
num_retriesMaximum number of retries.
req_typeType of the request (used for logging retries).
sleepFunctions to sleep for random time between retries.
randFunctions to sleep for random time between retries.
uriURI to be requested.
methodHTTP method to be used.
*argsAdditional arguments passed to http.request.
**kwargsAdditional arguments passed to http.request.
Returns
resp, content - Response from the http request (may be HTTP 5xx).
def _should_retry_response(resp_status, content):

Determines whether a response should be retried.

Parameters
resp_statusThe response status received.
contentThe response content body.
Returns
True if the response should be retried, otherwise False.
_LEGACY_BATCH_URI: str =

Undocumented

Value
'https://www.googleapis.com/batch'
_TOO_MANY_REQUESTS: int =

Undocumented

Value
429