From 6db9fa96482354a5b72efe24e7bc51448c5c621a Mon Sep 17 00:00:00 2001 From: Edward Kotarski Date: Wed, 29 Jan 2025 10:19:51 +0000 Subject: [PATCH] retry http bad status --- gator/common/http_api.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gator/common/http_api.py b/gator/common/http_api.py index 9f720b5..c7af3d8 100644 --- a/gator/common/http_api.py +++ b/gator/common/http_api.py @@ -56,7 +56,7 @@ async def get(self, route: str) -> Dict[str, str]: full_url = f"http://{self.url}{self.ROUTE_PREFIX}/{route}" for _ in range(self.retries): try: - async with self.session.get(full_url) as resp: + async with self.session.get(full_url, raise_for_status=True) as resp: data = await resp.json() if data.get("result", None) != "success": print( @@ -64,7 +64,7 @@ async def get(self, route: str) -> Dict[str, str]: file=sys.stderr, ) return data - except aiohttp.ClientConnectionError: + except (aiohttp.ClientConnectionError, aiohttp.ClientResponseError): await asyncio.sleep(self.delay) else: print( @@ -89,7 +89,9 @@ async def post(self, route: str, **kwargs: Any) -> Dict[str, str]: full_url = f"http://{self.url}{self.ROUTE_PREFIX}/{route}" for _ in range(10): try: - async with self.session.post(full_url, json=kwargs) as resp: + async with self.session.post( + full_url, json=kwargs, raise_for_status=True + ) as resp: data = await resp.json() if data.get("result", None) != "success": print( @@ -97,7 +99,7 @@ async def post(self, route: str, **kwargs: Any) -> Dict[str, str]: file=sys.stderr, ) return data - except aiohttp.ClientConnectionError: + except (aiohttp.ClientConnectionError, aiohttp.ClientResponseError): await asyncio.sleep(0.1) else: print(