0

I unexpectedly am receiving a keyError when I try to access 'deletionTime' on the User resource object after successfully retrieving a user object from a Users.get call.

I tried printing all the keys of the returned user by executing print(user.keys()). 'deletionTime' is not listed, but it is shown in the documentation, https://developers.google.com/admin-sdk/directory/v1/reference/users

user_service = build('admin', 'directory_v1', credentials=d_creds)
user = user_service.users().get(userKey=userkey).execute()

if not user:
   print('user not found')
else:
   UserObj.fullName = user['name']['fullName']
   UserObj.lastLoginTime = user['lastLoginTime']
   UserObj.creationTime = user['creationTime']
   UserObj.deletionTime = user['deletionTime']
   UserObj.suspended = user['suspended']

Expected: ability to retrieve the deletionTime of a user Actual: KeyError: 'deletionTime'

hnac
  • 1

1 Answers1

0

It's possible that the deletionTime does not exist if the user account was not actually deleted. Can you confirm the user was actually deleted?

If this is the case, you may just want to use Python's get method to try and retrieve the value safely 1. get() will allow you to set a default value if the key-value pair is not in the user dictionary.

brugz
  • 52
  • 2
  • Performing a users.get on a user that was deleted results in a "resource not found" exception. So, it appears 'deletionTime' really is irrelevant.. – hnac Aug 15 '19 at 16:09