From ef9cd7e85c9d76ce7d0a5e738062c2d7a31e3fbe Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Tue, 17 Oct 2023 06:05:30 +0000 Subject: [PATCH] Resolve "Fix coingecko too many requests error" --- common/cg_Crypto.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/cg_Crypto.py b/common/cg_Crypto.py index 82071ca..4ba41a0 100644 --- a/common/cg_Crypto.py +++ b/common/cg_Crypto.py @@ -9,6 +9,8 @@ from markdownify import markdownify from common.Symbol import Coin from common.utilities import rate_limited +import time + log = logging.getLogger(__name__) @@ -34,6 +36,12 @@ class cg_Crypto: url = "https://api.coingecko.com/api/v3" + endpoint resp = r.get(url, params=params, timeout=timeout) # Make sure API returned a proper status code + + if resp.status_code == 429: + log.warning(f"CoinGecko returned 429 - Too Many Requests for endpoint: {endpoint}. Sleeping and trying again.") + time.sleep(10) + return self.get(endpoint=endpoint, params=params, timeout=timeout) + try: resp.raise_for_status() except r.exceptions.HTTPError as e: