google.resumable_media.common module

Common utilities for Google Media Downloads and Resumable Uploads.

google.resumable_media.common.MAX_CUMULATIVE_RETRY = 600.0

float – 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.

google.resumable_media.common.MAX_SLEEP = 64.0

float – 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.

google.resumable_media.common.PERMANENT_REDIRECT = 308

int – Permanent redirect status code.

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

http.client.PERMANENT_REDIRECT was added in Python 3.5, so can’t be used in a “general” code base.

For more information, see RFC 7238.

class google.resumable_media.common.RetryStrategy(max_sleep=64.0, max_cumulative_retry=None, max_retries=None)

Bases: object

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.
max_sleep

float – Maximum amount of time allowed between requests.

max_cumulative_retry

Optional [ float ] – Maximum total sleep time allowed during retry process.

max_retries

Optional [ int ] – The number retries to attempt.

Raises:ValueError – If both of max_cumulative_retry and max_retries are passed.
retry_allowed(total_sleep, num_retries)

Check if another retry is allowed.

Parameters:
  • total_sleep (float) – The amount of sleep accumulated by the caller.
  • num_retries (int) – The number of retries already 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 = 429

int – Status code indicating rate-limiting.

http.client.TOO_MANY_REQUESTS was added in Python 3.3, so can’t be used in a “general” code base.

For more information, see RFC 6585.

google.resumable_media.common.UPLOAD_CHUNK_SIZE = 262144

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