aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfwaggle <[email protected]>2022-11-05 14:52:06 +1100
committerfwaggle <[email protected]>2022-11-05 14:52:06 +1100
commitb69e998cebcf60052a0ccfa76bce073f9817df65 (patch)
tree6a9df739482575cba866bf4bbd0c4041fe0cc5ab
parent89a6bd2baca4e651440402773393c19f74ee0993 (diff)
downloadmastodon.py-b69e998cebcf60052a0ccfa76bce073f9817df65.tar.gz
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
-rw-r--r--mastodon/Mastodon.py7
1 files 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:
3407 self.ratelimit_limit = int(response_object.headers['X-RateLimit-Limit']) 3407 self.ratelimit_limit = int(response_object.headers['X-RateLimit-Limit'])
3408 3408
3409 try: 3409 try:
3410 ratelimit_reset_datetime = dateutil.parser.parse(response_object.headers['X-RateLimit-Reset']) 3410 if str(int(response_object.headers['X-RateLimit-Reset'])) == response_object.headers['X-RateLimit-Reset']:
3411 self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime) 3411 self.ratelimit_reset = int(response_object.headers['X-RateLimit-Reset'])
3412 else:
3413 ratelimit_reset_datetime = dateutil.parser.parse(response_object.headers['X-RateLimit-Reset'])
3414 self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime)
3412 3415
3413 # Adjust server time to local clock 3416 # Adjust server time to local clock
3414 if 'Date' in response_object.headers: 3417 if 'Date' in response_object.headers:
Powered by cgit v1.2.3 (git 2.41.0)