Skip to content

Commit 7448b43

Browse files
committed
Bug: Catch any underlying exceptions from http.HTTPException
Resolves https://github.com/GoogleCloudPlatform/google-auth-library- python-httplib2/issues/6
1 parent 73ca3dd commit 7448b43

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

google_auth_httplib2.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from google.auth import exceptions
2222
from google.auth import transport
2323
import httplib2
24-
24+
from http.client import HTTPException
2525

2626
_LOGGER = logging.getLogger(__name__)
2727
# Properties present in file-like streams / buffers.
@@ -194,8 +194,15 @@ def request(self, uri, method='GET', body=None, headers=None,
194194
body_stream_position = body.tell()
195195

196196
# Make the request.
197-
response, content = self.http.request(
198-
uri, method, body=body, headers=request_headers, **kwargs)
197+
try:
198+
response, content = self.http.request(
199+
uri, method, body=body, headers=request_headers, **kwargs)
200+
# TODO: httplib2 should catch the lower http error, this is a bug and
201+
# needs to be fixed there. Catch the error for the meanwhile.
202+
except (httplib2.HttpLib2Error, HTTPException) as exc:
203+
_LOGGER.exception('Caught exception from http, reraising %r.',
204+
exc)
205+
raise exceptions.TransportError(exc)
199206

200207
# If the response indicated that the credentials needed to be
201208
# refreshed, then refresh the credentials and re-attempt the

0 commit comments

Comments
 (0)