From 798510511fa6e0e6717a5cb2dd0875d97d43e473 Mon Sep 17 00:00:00 2001 From: Max Erenberg Date: Sun, 7 Nov 2021 01:12:49 -0400 Subject: [PATCH] fix first/last name script --- one_time_scripts/first_and_last_names.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/one_time_scripts/first_and_last_names.py b/one_time_scripts/first_and_last_names.py index 8a4701c..bba1c5d 100644 --- a/one_time_scripts/first_and_last_names.py +++ b/one_time_scripts/first_and_last_names.py @@ -30,15 +30,12 @@ for csc_entry in csc_conn.entries: cn = csc_entry.cn.value sn = None given_name = None - try: - uw_conn.search( - f'uid={uid},{UWLDAP_MEMBERS_BASE}', '(objectClass=*)', - attributes=['sn', 'givenName'], search_scope=ldap3.BASE) + uw_conn.search( + UWLDAP_MEMBERS_BASE, f'(uid={uid})', attributes=['sn', 'givenName']) + if uw_conn.entries: uw_entry = uw_conn.entries[0] sn = uw_entry.sn.value given_name = uw_entry.givenName.value - except ldap3.core.exceptions.LDAPNoSuchObjectResult: - pass if given_name is None or sn is None: print(f'WARNING: could not retrieve first and last names for {uid}; inferring from whitespace instead') words = cn.split()