From 036eca5303bd80a9bc0e68829ff5eb42e4be5f59 Mon Sep 17 00:00:00 2001 From: javalladares Date: Thu, 21 Dec 2023 23:39:11 +0000 Subject: [PATCH] Fix issue #1441 Simplifying thoubleshooting by capturing last seen exception to set is as the direct cause of the `exceptions.TransportError` --- google/auth/compute_engine/_metadata.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google/auth/compute_engine/_metadata.py b/google/auth/compute_engine/_metadata.py index 1c884c3c4..aedd45220 100644 --- a/google/auth/compute_engine/_metadata.py +++ b/google/auth/compute_engine/_metadata.py @@ -199,6 +199,7 @@ def get( url = _helpers.update_query(base_url, query_params) retries = 0 + last_exception = None while retries < retry_count: try: response = request(url=url, method="GET", headers=headers_to_use) @@ -213,11 +214,12 @@ def get( e, ) retries += 1 + last_exception = e else: raise exceptions.TransportError( "Failed to retrieve {} from the Google Compute Engine " "metadata service. Compute Engine Metadata server unavailable".format(url) - ) + ) from last_exception content = _helpers.from_bytes(response.data)