workaround some 500

This commit is contained in:
Your Name 2022-05-05 15:20:13 -04:00
parent 3260b12065
commit 583172a1e3

View file

@ -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']