Rate limiter: fix datetime parser (fixes #5)

This commit is contained in:
lucdev 2022-12-28 11:09:37 -03:00 committed by Kay Faraday
parent e2a18f8888
commit d932256125
1 changed files with 2 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import platform
import contextlib
from functools import wraps
from datetime import datetime, timezone
from dateutil.parser import parse as parsedate
def http_session_factory(headers={}, **kwargs):
user_agent = (
@ -73,7 +74,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__()