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.

google-auth-httplib2

Transport adapter for httplib2.

class google_auth_httplib2.AuthorizedHttp(credentials, http=None, refresh_status_codes=(<HTTPStatus.UNAUTHORIZED: 401>, ), max_refresh_attempts=2)[source]

Bases: object

A httplib2 HTTP class with credentials.

This class is used to perform requests to API endpoints that require authorization:

from google.auth.transport._httplib2 import AuthorizedHttp

authed_http = AuthorizedHttp(credentials)

response = authed_http.request(
    'https://www.googleapis.com/storage/v1/b')

This class implements request() in the same way as httplib2.Http and can usually be used just like any other instance of httplib2.Http.

The underlying request() implementation handles adding the credentials’ headers to the request and refreshing credentials as needed.

Parameters
  • credentials (google.auth.credentials.Credentials) – The credentials to add to the request.

  • http (httplib2.Http) – The underlying HTTP object to use to make requests. If not specified, a httplib2.Http instance will be constructed.

  • refresh_status_codes (Sequence[int]) – Which HTTP status codes indicate that credentials should be refreshed and the request should be retried.

  • max_refresh_attempts (int) – The maximum number of times to attempt to refresh the credentials and retry the request.

add_certificate(key, cert, domain, password=None)[source]

Proxy to httplib2.Http.add_certificate.

close()[source]

Calls httplib2’s Http.close

property connections

Proxy to httplib2.Http.connections.

property follow_redirects

Proxy to httplib2.Http.follow_redirects.

property redirect_codes

Proxy to httplib2.Http.redirect_codes.

request(uri, method='GET', body=None, headers=None, redirections=5, connection_type=None, **kwargs)[source]

Implementation of httplib2’s Http.request.

property timeout

Proxy to httplib2.Http.timeout.

class google_auth_httplib2.Request(http)[source]

Bases: google.auth.transport.Request

httplib2 request adapter.

This class is used internally for making requests using various transports in a consistent way. If you use AuthorizedHttp you do not need to construct or use this class directly.

This class can be useful if you want to manually refresh a Credentials instance:

import google_auth_httplib2
import httplib2

http = httplib2.Http()
request = google_auth_httplib2.Request(http)

credentials.refresh(request)
Parameters

http (httplib2.Http) – The underlying http object to use to make requests.

__call__(url, method='GET', body=None, headers=None, timeout=None, **kwargs)[source]

Make an HTTP request using httplib2.

Parameters
  • url (str) – The URI to be requested.

  • method (str) – The HTTP method to use for the request. Defaults to ‘GET’.

  • body (bytes) – The payload / body in HTTP request.

  • headers (Mapping[str, str]) – Request headers.

  • timeout (Optional[int]) – The number of seconds to wait for a response from the server. This is ignored by httplib2 and will issue a warning.

  • kwargs – Additional arguments passed throught to the underlying httplib2.Http.request() method.

Returns

The HTTP response.

Return type

google.auth.transport.Response

Raises

google.auth.exceptions.TransportError – If any exception occurred.