From 497ef1faed822c400dd75fc3ee7f8cc23aeb087e Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Thu, 21 May 2026 15:51:01 +0000 Subject: [PATCH] =?UTF-8?q?GoogleSolarApiClient=20retries=20on=20transient?= =?UTF-8?q?=20HTTP=20errors=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solar/google_solar_api_client.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/infrastructure/solar/google_solar_api_client.py b/infrastructure/solar/google_solar_api_client.py index 4edea335..9112b980 100644 --- a/infrastructure/solar/google_solar_api_client.py +++ b/infrastructure/solar/google_solar_api_client.py @@ -1,4 +1,5 @@ -from typing import Any, Literal +import time +from typing import Any, Literal, Optional import requests @@ -28,7 +29,16 @@ class GoogleSolarApiClient: "requiredQuality": required_quality, "key": self._api_key, } - response = requests.get(insights_url, params=params) - response.raise_for_status() - result: dict[str, Any] = response.json() - return result + last_exc: Optional[Exception] = None + for attempt in range(self.MAX_RETRIES): + try: + response = requests.get(insights_url, params=params) + response.raise_for_status() + result: dict[str, Any] = response.json() + return result + except requests.exceptions.RequestException as e: + last_exc = e + time.sleep(2 ** attempt) + + assert last_exc is not None + raise last_exc