From 4f961af43cc6158a223d53ee9aef5d6ccc35ec8f Mon Sep 17 00:00:00 2001 From: Security & Stuff <74931194+SecurityAndStuff@users.noreply.github.com> Date: Fri, 12 May 2023 15:53:56 +0100 Subject: [PATCH] handle rate limit correctly Signed-off-by: ssousa-mwb <74931194+SecurityAndStuff@users.noreply.github.com> --- src/ghas_cli/utils/network.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ghas_cli/utils/network.py b/src/ghas_cli/utils/network.py index 601ecac..f6ac06c 100644 --- a/src/ghas_cli/utils/network.py +++ b/src/ghas_cli/utils/network.py @@ -33,7 +33,11 @@ def check_rate_limit(response: Any) -> bool: f"Rate limit reached: {response.headers['x-ratelimit-remaining']}/{response.headers['x-ratelimit-limit']} - {reset_time}" ) - time.sleep(int(response.headers["x-ratelimit-remaining"])) + time_to_wait = int(reset_time.timestamp()) - (time.time()) + + logging.info(f"Waiting {time_to_wait} seconds before retrying.") + time.sleep(time_to_wait) + return True if response.status_code == 403: