aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 27c98af..f55d4bb 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -2214,9 +2214,12 @@ class Mastodon:
2214 if not response_object.ok: 2214 if not response_object.ok:
2215 try: 2215 try:
2216 response = response_object.json(object_hook=self.__json_hooks) 2216 response = response_object.json(object_hook=self.__json_hooks)
2217 if not isinstance(response, dict) or 'error' not in response: 2217 if isinstance(response, dict) and 'error' in response:
2218 error_msg = response['error']
2219 elif isinstance(response, str):
2220 error_msg = response
2221 else:
2218 error_msg = None 2222 error_msg = None
2219 error_msg = response['error']
2220 except ValueError: 2223 except ValueError:
2221 error_msg = None 2224 error_msg = None
2222 2225
@@ -2274,13 +2277,17 @@ class Mastodon:
2274 if url['rel'] == 'next': 2277 if url['rel'] == 'next':
2275 # Be paranoid and extract max_id specifically 2278 # Be paranoid and extract max_id specifically
2276 next_url = url['url'] 2279 next_url = url['url']
2277 matchgroups = re.search(r"max_id=([0-9]*)", next_url) 2280 matchgroups = re.search(r"[?&]max_id=([^&]+)", next_url)
2278 2281
2279 if matchgroups: 2282 if matchgroups:
2280 next_params = copy.deepcopy(params) 2283 next_params = copy.deepcopy(params)
2281 next_params['_pagination_method'] = method 2284 next_params['_pagination_method'] = method
2282 next_params['_pagination_endpoint'] = endpoint 2285 next_params['_pagination_endpoint'] = endpoint
2283 next_params['max_id'] = int(matchgroups.group(1)) 2286 max_id = matchgroups.group(1)
2287 if max_id.isdigit():
2288 next_params['max_id'] = int(max_id)
2289 else:
2290 next_params['max_id'] = max_id
2284 if "since_id" in next_params: 2291 if "since_id" in next_params:
2285 del next_params['since_id'] 2292 del next_params['since_id']
2286 response[-1]._pagination_next = next_params 2293 response[-1]._pagination_next = next_params
@@ -2288,13 +2295,17 @@ class Mastodon:
2288 if url['rel'] == 'prev': 2295 if url['rel'] == 'prev':
2289 # Be paranoid and extract since_id specifically 2296 # Be paranoid and extract since_id specifically
2290 prev_url = url['url'] 2297 prev_url = url['url']
2291 matchgroups = re.search(r"since_id=([0-9]*)", prev_url) 2298 matchgroups = re.search(r"[?&]since_id=([^&]+)", prev_url)
2292 2299
2293 if matchgroups: 2300 if matchgroups:
2294 prev_params = copy.deepcopy(params) 2301 prev_params = copy.deepcopy(params)
2295 prev_params['_pagination_method'] = method 2302 prev_params['_pagination_method'] = method
2296 prev_params['_pagination_endpoint'] = endpoint 2303 prev_params['_pagination_endpoint'] = endpoint
2297 prev_params['since_id'] = int(matchgroups.group(1)) 2304 since_id = matchgroups.group(1)
2305 if since_id.isdigit():
2306 prev_params['since_id'] = int(since_id)
2307 else:
2308 prev_params['since_id'] = since_id
2298 if "max_id" in prev_params: 2309 if "max_id" in prev_params:
2299 del prev_params['max_id'] 2310 del prev_params['max_id']
2300 response[0]._pagination_prev = prev_params 2311 response[0]._pagination_prev = prev_params
Powered by cgit v1.2.3 (git 2.41.0)