Skip to content

Commit af61fac

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 af61fac

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

google_auth_httplib2.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
from google.auth import transport
2323
import httplib2
2424

25+
# httplib became http.client in 3.x
26+
try:
27+
from http.client import HTTPException
28+
except ImportError:
29+
from httplib import HTTPException
2530

2631
_LOGGER = logging.getLogger(__name__)
2732
# Properties present in file-like streams / buffers.
@@ -115,7 +120,9 @@ def __call__(self, url, method='GET', body=None, headers=None,
115120
response, data = self.http.request(
116121
url, method=method, body=body, headers=headers, **kwargs)
117122
return _Response(response, data)
118-
except httplib2.HttpLib2Error as exc:
123+
# TODO: httplib2 should catch the lower http error, this is a bug and
124+
# needs to be fixed there. Catch the error for the meanwhile.
125+
except (httplib2.HttpLib2Error, HTTPException) as exc:
119126
raise exceptions.TransportError(exc)
120127

121128

0 commit comments

Comments
 (0)