diff options
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index fc585ba..98cebab 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 | ||
@@ -2272,13 +2275,17 @@ class Mastodon: | |||
2272 | if url['rel'] == 'next': | 2275 | if url['rel'] == 'next': |
2273 | # Be paranoid and extract max_id specifically | 2276 | # Be paranoid and extract max_id specifically |
2274 | next_url = url['url'] | 2277 | next_url = url['url'] |
2275 | matchgroups = re.search(r"max_id=([0-9]*)", next_url) | 2278 | matchgroups = re.search(r"[?&]max_id=([^&]+)", next_url) |
2276 | 2279 | ||
2277 | if matchgroups: | 2280 | if matchgroups: |
2278 | next_params = copy.deepcopy(params) | 2281 | next_params = copy.deepcopy(params) |
2279 | next_params['_pagination_method'] = method | 2282 | next_params['_pagination_method'] = method |
2280 | next_params['_pagination_endpoint'] = endpoint | 2283 | next_params['_pagination_endpoint'] = endpoint |
2281 | next_params['max_id'] = int(matchgroups.group(1)) | 2284 | max_id = matchgroups.group(1) |
2285 | if max_id.isdigit(): | ||
2286 | next_params['max_id'] = int(max_id) | ||
2287 | else: | ||
2288 | next_params['max_id'] = max_id | ||
2282 | if "since_id" in next_params: | 2289 | if "since_id" in next_params: |
2283 | del next_params['since_id'] | 2290 | del next_params['since_id'] |
2284 | response[-1]._pagination_next = next_params | 2291 | response[-1]._pagination_next = next_params |
@@ -2286,13 +2293,17 @@ class Mastodon: | |||
2286 | if url['rel'] == 'prev': | 2293 | if url['rel'] == 'prev': |
2287 | # Be paranoid and extract since_id specifically | 2294 | # Be paranoid and extract since_id specifically |
2288 | prev_url = url['url'] | 2295 | prev_url = url['url'] |
2289 | matchgroups = re.search(r"since_id=([0-9]*)", prev_url) | 2296 | matchgroups = re.search(r"[?&]since_id=([^&]+)", prev_url) |
2290 | 2297 | ||
2291 | if matchgroups: | 2298 | if matchgroups: |
2292 | prev_params = copy.deepcopy(params) | 2299 | prev_params = copy.deepcopy(params) |
2293 | prev_params['_pagination_method'] = method | 2300 | prev_params['_pagination_method'] = method |
2294 | prev_params['_pagination_endpoint'] = endpoint | 2301 | prev_params['_pagination_endpoint'] = endpoint |
2295 | prev_params['since_id'] = int(matchgroups.group(1)) | 2302 | since_id = matchgroups.group(1) |
2303 | if since_id.isdigit(): | ||
2304 | prev_params['since_id'] = int(since_id) | ||
2305 | else: | ||
2306 | prev_params['since_id'] = since_id | ||
2296 | if "max_id" in prev_params: | 2307 | if "max_id" in prev_params: |
2297 | del prev_params['max_id'] | 2308 | del prev_params['max_id'] |
2298 | response[0]._pagination_prev = prev_params | 2309 | response[0]._pagination_prev = prev_params |