0

Every time I run this code with a wild card (max_users = '*') or >140 I get this error JSONDecodeError: Expecting value: line 1 column 1 (char 0). But are <140 value it works fine not just all the user are returned.

What am I doing wrong?

 def datetime_of_last_login(user) -> dt.datetime:
 timestamp_of_last_login = int(user.lastLogin / 1000)
 last_login = dt.datetime.fromtimestamp(timestamp_of_last_login)
 return last_login
def num_days_since_last_login(user) -> int:
 last_login = datetime_of_last_login(user)
 now = dt.datetime.now()
 return (now - last_login).days
 
users = gis.users.search(query='*', max_users=140)
for user in users:
 cd = dt.datetime.fromtimestamp(user.created / 1000).strftime('%Y-%m-%d %H:%M:%S')
 last_login_datetime = datetime_of_last_login(user)
 days_since_last_login = num_days_since_last_login(user)
 print("_____________________________________________________________")
 print(f"User: {user.username}")
 print(f"Role: {user.role}")
 print(f"Email: {user.email}")
 print("Creation Date:", cd)
 print("Last Login:", last_login_datetime)
 print("Days Since Last Login:", days_since_last_login)
 
 if days_since_last_login > 90:
 print (f"User:{user.username}")
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 4, 2023 at 14:13

1 Answer 1

0

The solution was pagination. The user list is large thus there is need to pull in bit using this code

start = 0
lenght_searchresult = 100
while lenght_searchresult == 100:
 source_users = source.users.advanced_search(query='!esri_ & !portaladmin', start = start, max_users = 100)
 list_users = source_users.get('results')
 lenght_searchresult = len(list_users)
 start = start + 100
 for user in list_users:
 print(user.username)
answered Aug 11, 2023 at 13:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.