From 583172a1e33faeb6b1b63246476fe9738f634e88 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 5 May 2022 15:20:13 -0400 Subject: [PATCH] workaround some 500 --- mastodon/api.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mastodon/api.py b/mastodon/api.py index bfe2e0c2..1fd3125f 100644 --- a/mastodon/api.py +++ b/mastodon/api.py @@ -156,12 +156,16 @@ def get_site_id(username, user_site, target_site, token): 'Authorization': f'Bearer {token}' } response = get(url, params=payload, headers=headers) - data = response.json() - if 'accounts' not in data: + try: + data = response.json() + except Exception: + logger.error(f"Error parsing JSON from {url}") + return None + if 'accounts' not in data: return None elif len(data['accounts']) == 0: # target site may return empty if no cache of this user return None - elif data['accounts'][0]['acct'] != f"{username}@{user_site}": # or return another user with a similar id which needs to be skipped + elif data['accounts'][0]['acct'] != f"{username}@{user_site}": # or return another user with a similar id which needs to be skipped return None else: return data['accounts'][0]['id']