oauth2client.transport module

class oauth2client.transport.MemoryCache[source]

Bases: object

httplib2 Cache implementation which only caches locally.

delete(key)[source]
get(key)[source]
set(key, value)[source]
oauth2client.transport.clean_headers(headers)[source]

Forces header keys and values to be strings, i.e not unicode.

The httplib module just concats the header keys and values in a way that may make the message header a unicode string, which, if it then tries to contatenate to a binary request body may result in a unicode decode error.

Parameters:headers – dict, A dictionary of headers.
Returns:The same dictionary but with all the keys converted to strings.
oauth2client.transport.get_cached_http()[source]

Return an HTTP object which caches results returned.

This is intended to be used in methods like oauth2client.client.verify_id_token(), which calls to the same URI to retrieve certs.

Returns:httplib2.Http, an HTTP object with a MemoryCache
oauth2client.transport.get_http_object(*args, **kwargs)[source]

Return a new HTTP object.

Parameters:
  • *args – tuple, The positional arguments to be passed when contructing a new HTTP object.
  • **kwargs – dict, The keyword arguments to be passed when contructing a new HTTP object.
Returns:

httplib2.Http, an HTTP object.

oauth2client.transport.request(http, uri, method='GET', body=None, headers=None, redirections=5, connection_type=None)[source]

Make an HTTP request with an HTTP object and arguments.

Parameters:
  • http – httplib2.Http, an http object to be used to make requests.
  • uri – string, The URI to be requested.
  • method – string, The HTTP method to use for the request. Defaults to ‘GET’.
  • body – string, The payload / body in HTTP request. By default there is no payload.
  • headers – dict, Key-value pairs of request headers. By default there are no headers.
  • redirections – int, The number of allowed 203 redirects for the request. Defaults to 5.
  • connection_type – httplib.HTTPConnection, a subclass to be used for establishing connection. If not set, the type will be determined from the uri.
Returns:

tuple, a pair of a httplib2.Response with the status code and other headers and the bytes of the content returned.

oauth2client.transport.wrap_http_for_auth(credentials, http)[source]

Prepares an HTTP object’s request method for auth.

Wraps HTTP requests with logic to catch auth failures (typically identified via a 401 status code). In the event of failure, tries to refresh the token used and then retry the original request.

Parameters:
  • credentials – Credentials, the credentials used to identify the authenticated user.
  • http – httplib2.Http, an http object to be used to make auth requests.
oauth2client.transport.wrap_http_for_jwt_access(credentials, http)[source]

Prepares an HTTP object’s request method for JWT access.

Wraps HTTP requests with logic to catch auth failures (typically identified via a 401 status code). In the event of failure, tries to refresh the token used and then retry the original request.

Parameters:
  • credentials – _JWTAccessCredentials, the credentials used to identify a service account that uses JWT access tokens.
  • http – httplib2.Http, an http object to be used to make auth requests.