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(-) (limited to 'mastodon') 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 From 144a4e2b9bdfd371e651f965f21018dc4dd77fd4 Mon Sep 17 00:00:00 2001 From: fwaggle Date: Sat, 5 Nov 2022 15:01:28 +1100 Subject: Fix version crash when connecting to gotosocial While gotosocial has a PR open to send a Mastodon-compatible version in the `instance` endpoint, whatever it sends is unlikely to be helpful for the purpose of version-gating features in the client library. You can disable version-gating, but it still fails on instantiating due to GtS's version not matching the semver regex. Fix this by moving the version_check_mode above it, and not parsing the version if it's turned off. --- mastodon/Mastodon.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index f6b9f1c..f1a9c5c 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -421,20 +421,20 @@ class Mastodon: if not (self.api_base_url is None or try_base_url == self.api_base_url): raise MastodonIllegalArgumentError('Mismatch in base URLs between files and/or specified') self.api_base_url = try_base_url + + if not version_check_mode in ["created", "changed", "none"]: + raise MastodonIllegalArgumentError("Invalid version check method.") + self.version_check_mode = version_check_mode # Versioning - if mastodon_version == None: + if mastodon_version == None and self.version_check_mode != 'none': self.retrieve_mastodon_version() - else: + elif self.version_check_mode != 'none': try: self.mastodon_major, self.mastodon_minor, self.mastodon_patch = parse_version_string(mastodon_version) except: raise MastodonVersionError("Bad version specified") - if not version_check_mode in ["created", "changed", "none"]: - raise MastodonIllegalArgumentError("Invalid version check method.") - self.version_check_mode = version_check_mode - # Ratelimiting parameter check if ratelimit_method not in ["throw", "wait", "pace"]: raise MastodonIllegalArgumentError("Invalid ratelimit method.") -- cgit v1.2.3