From b69e998cebcf60052a0ccfa76bce073f9817df65 Mon Sep 17 00:00:00 2001 From: fwaggle Date: Sat, 5 Nov 2022 14:52:06 +1100 Subject: Handle UNIX Epoch times in X-RateLimit-Reset Instead of returning an ISO8601 timestamp, gotosocial returns an integer UNIX Epoch for the X-RateLimit-Reset header. As `dateutil.parser.parse` doesn't handle these, I do a naive check to see if the header is an integer and don't parse it if so. Fixes #246 --- mastodon/Mastodon.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index ef428d2..f6b9f1c 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -3407,8 +3407,11 @@ class Mastodon: self.ratelimit_limit = int(response_object.headers['X-RateLimit-Limit']) try: - ratelimit_reset_datetime = dateutil.parser.parse(response_object.headers['X-RateLimit-Reset']) - self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime) + if str(int(response_object.headers['X-RateLimit-Reset'])) == response_object.headers['X-RateLimit-Reset']: + self.ratelimit_reset = int(response_object.headers['X-RateLimit-Reset']) + else: + ratelimit_reset_datetime = dateutil.parser.parse(response_object.headers['X-RateLimit-Reset']) + self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime) # Adjust server time to local clock if 'Date' in response_object.headers: -- cgit v1.2.3