From 82320560a139d95558d135da11bfefd8e9782471 Mon Sep 17 00:00:00 2001 From: lucdev Date: Wed, 28 Dec 2022 11:09:37 -0300 Subject: [PATCH] Rate limiter: fix datetime parser (fixes #5) --- utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils.py b/utils.py index 8bb1daa..4a802d6 100644 --- a/utils.py +++ b/utils.py @@ -4,6 +4,7 @@ import anyio import contextlib from functools import wraps from datetime import datetime, timezone +from dateutil.parser import parse as parsedate def as_corofunc(f): @wraps(f) @@ -60,7 +61,7 @@ class _RateLimitContextManager(contextlib.AbstractAsyncContextManager): if resp.headers.get('X-RateLimit-Remaining') not in {'0', '1'}: return resp - await sleep_until(datetime.fromisoformat(resp.headers['X-RateLimit-Reset'])) + await sleep_until(parsedate(resp.headers['X-RateLimit-Reset'])) await self._request_cm.__aexit__(*(None,)*3) return await self.__aenter__()