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