From b20118810f72b15ebb569199fdfeb4162de81a66 Mon Sep 17 00:00:00 2001 From: Henri Wahl Date: Tue, 23 Feb 2021 10:23:15 +0100 Subject: [PATCH] catch JSON decode error if no LDAP users exist --- seafadm | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/seafadm b/seafadm index 03315c0..5b570d2 100755 --- a/seafadm +++ b/seafadm @@ -575,20 +575,27 @@ def get_users(): users = dict() # returned lsit of users comes in different dictionaries in JSON for user_db in USER_API_KEYS: - result = json.loads(get_ajax(f'/api/v2.1/admin/{user_db}?per_page={PER_PAGE}')) - if result.get(USER_API_KEYS[user_db]): - for item in result[USER_API_KEYS[user_db]]: - # LDAP users do not have name property - just use mail address instead - user = User(name=item.get('name', item['email']), - id=item['email'], - mail=item['email'], - creation=item['create_time'], - used_space=int(item['quota_usage']/1000000), - quota=int(item['quota_total']/1000000) - ) - users[user.id] = user + url = f'/api/v2.1/admin/{user_db}?per_page={PER_PAGE}' + ajax = get_ajax(url) + try: + result = json.loads(get_ajax(f'/api/v2.1/admin/{user_db}?per_page={PER_PAGE}')) + if result.get(USER_API_KEYS[user_db]): + for item in result[USER_API_KEYS[user_db]]: + # LDAP users do not have name property - just use mail address instead + user = User(name=item.get('name', item['email']), + id=item['email'], + mail=item['email'], + creation=item['create_time'], + used_space=int(item['quota_usage']/1000000), + quota=int(item['quota_total']/1000000) + ) + users[user.id] = user + except json.JSONDecodeError: + # no valid JSON given, for example if there are no LDAP users + pass return users + def get_libaries(): """ retrieve information about all libraries