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 ashttplib2.Http
and can usually be used just like any other instance ofhttplib2.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.
- 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.
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
- Raises
google.auth.exceptions.TransportError – If any exception occurred.