As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

Common Utilities

Common utilities for Google Media Downloads and Resumable Uploads.

Includes custom exception types, useful constants and shared helpers.

exception google.resumable_media.common.DataCorruption(response, *args)[source]

Error class for corrupt media transfers.

Parameters
  • response (object) – The HTTP response which caused the failure.

  • args (tuple) – The positional arguments typically passed to an exception class.

response

The HTTP response object that caused the failure.

Type

object

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception google.resumable_media.common.InvalidResponse(response, *args)[source]

Error class for responses which are not in the correct state.

Parameters
  • response (object) – The HTTP response which caused the failure.

  • args (tuple) – The positional arguments typically passed to an exception class.

response

The HTTP response object that caused the failure.

Type

object

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

google.resumable_media.common.MAX_CUMULATIVE_RETRY = 600.0

Maximum total sleep time allowed during retry process.

This is provided (10 minutes) as a default. When the cumulative sleep exceeds this limit, no more retries will occur.

Type

float

google.resumable_media.common.MAX_SLEEP = 64.0

Maximum amount of time allowed between requests.

Used during the retry process for sleep after a failed request. Chosen since it is the power of two nearest to one minute.

Type

float

google.resumable_media.common.PERMANENT_REDIRECT = HTTPStatus.PERMANENT_REDIRECT

Permanent redirect status code.

Note

This is a backward-compatibility alias.

It is used by Google services to indicate some (but not all) of a resumable upload has been completed.

For more information, see RFC 7238.

Type

int

google.resumable_media.common.RETRYABLE = (<HTTPStatus.TOO_MANY_REQUESTS: 429>, <HTTPStatus.REQUEST_TIMEOUT: 408>, <HTTPStatus.INTERNAL_SERVER_ERROR: 500>, <HTTPStatus.BAD_GATEWAY: 502>, <HTTPStatus.SERVICE_UNAVAILABLE: 503>, <HTTPStatus.GATEWAY_TIMEOUT: 504>)

HTTP status codes that indicate a retryable error.

Connection errors are also retried, but are not listed as they are exceptions, not status codes.

Type

iterable

class google.resumable_media.common.RetryStrategy(max_sleep=64.0, max_cumulative_retry=None, max_retries=None, initial_delay=1.0, multiplier=2.0)[source]

Configuration class for retrying failed requests.

At most one of max_cumulative_retry and max_retries can be specified (they are both caps on the total number of retries). If neither are specified, then max_cumulative_retry is set as MAX_CUMULATIVE_RETRY.

Parameters
  • max_sleep (Optional[float]) – The maximum amount of time to sleep after a failed request. Default is MAX_SLEEP.

  • max_cumulative_retry (Optional[float]) – The maximum total amount of time to sleep during retry process.

  • max_retries (Optional[int]) – The number of retries to attempt.

  • initial_delay (Optional[float]) – The initial delay. Default 1.0 second.

  • muiltiplier (Optional[float]) – Exponent of the backoff. Default is 2.0.

max_sleep

Maximum amount of time allowed between requests.

Type

float

max_cumulative_retry

Maximum total sleep time allowed during retry process.

Type

Optional[float]

max_retries

The number retries to attempt.

Type

Optional[int]

initial_delay

The initial delay. Default 1.0 second.

Type

Optional[float]

muiltiplier

Exponent of the backoff. Default is 2.0.

Type

Optional[float]

Raises

ValueError – If both of max_cumulative_retry and max_retries are passed.

retry_allowed(total_sleep, num_retries)[source]

Check if another retry is allowed.

Parameters
  • total_sleep (float) – With another retry, the amount of sleep that will be accumulated by the caller.

  • num_retries (int) – With another retry, the number of retries that will be attempted by the caller.

Returns

Indicating if another retry is allowed (depending on either the cumulative sleep allowed or the maximum number of retries allowed.

Return type

bool

google.resumable_media.common.TOO_MANY_REQUESTS = HTTPStatus.TOO_MANY_REQUESTS

Status code indicating rate-limiting.

Note

This is a backward-compatibility alias.

For more information, see RFC 6585.

Type

int

google.resumable_media.common.UPLOAD_CHUNK_SIZE = 262144

Chunks in a resumable upload must come in multiples of 256 KB.

Type

int