Rate limiter: fix datetime parser (fixes #5)

This commit is contained in:
lucdev 2022-12-28 11:09:37 -03:00 committed by io
parent 6523a28e11
commit 82320560a1

View file

@ -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__()