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
pull/248/head
fwaggle 2022-11-05 14:52:06 +11:00
rodzic 89a6bd2bac
commit b69e998ceb
1 zmienionych plików z 5 dodań i 2 usunięć

Wyświetl plik

@ -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: