From d7d398e05a8913a3f4828725d8926f152b95b522 Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Sun, 2 Jun 2024 22:03:44 -0700 Subject: [PATCH] Never sleep in the first 5 seconds of a new rate limit period, as a workaround for a likely bug in the hypixel api. --- hypickle/hypixel.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hypickle/hypixel.py b/hypickle/hypixel.py index d935ccc..588ad23 100644 --- a/hypickle/hypixel.py +++ b/hypickle/hypixel.py @@ -55,7 +55,12 @@ def getJSON(typeOfRequest: str, uuid_or_ign: Optional[str], specific_api_key: Op f'typeOfRequest: {typeOfRequest}\nthere was a problem with response.json()' ) from e - if 'RateLimit-Remaining' in responseHeaders and int(responseHeaders['RateLimit-Remaining']) <= 1: + if ('RateLimit-Remaining' in responseHeaders and int(responseHeaders['RateLimit-Remaining']) <= 1 + and int(responseHeaders['RateLimit-Reset']) < 295): + # The < 295 condition is to not sleep when starting a new rate limit period, since it seems + # there's a bug in the api where the first response header gives a `RateLimit-Remaining` val that + # carries over from the previous period. + # Made an issue: https://github.com/HypixelDev/PublicAPI/issues/646 sleep_till = datetime.now() + timedelta(seconds=int(responseHeaders['RateLimit-Reset'])+1) if not responseJSON['success']: