Hello
I have a problem with the request rate limits using the Python SDK. Usually, the Python SDK handles the 429 errors, so if I do this:
for i in range(200):
print(i)
users_api.get_users_me()
It executes 180 requests, then it waits until the rate limit is reset, and then it does the final 20.
However, now I have a Script that is raising a 429 ApiException, and I don't know why.
The case scenario is this: I have a list of 100 user emails and a list of passwords, and I want to set their passwords using the API. So, it should do the 100 user search requests to get the ids, then 80 request to change the passwords until it reaches the 180 per minute limit, wait until it is reset, and finally make the last 20 requests.
However, when it should just wait, it is raising an ApiException of type 429, without dealing with it on its own.
The code is this:
users = [
'user1@domain.com',
'user2@domain.com',
'user3@domain.com',
# ...
'user98@domain.com',
'user99@domain.com',
'user100@domain.com',
]
passwords = [
'pass1',
'pass2',
'pass3',
# ...
'pass98',
'pass99',
'pass100',
]
# ... SDK Auth stuff ...
users_api = PureCloudPlatformClientV2.UsersApi()
def get_user_id_by_email(email):
body = PureCloudPlatformClientV2.UserSearchRequest()
query = PureCloudPlatformClientV2.UserSearchCriteria()
query.fields = ['email']
query.value = email
query.type = 'EXACT'
body.query=[query]
api_response = users_api.post_users_search(body)
return api_response.results[0].id
def change_password(user_id, new_password):
body = PureCloudPlatformClientV2.ChangePasswordRequest()
body.new_password = new_password
users_api.post_user_password(user_id, body)
for i in len(users):
user_id = get_user_id_by_email(users[i])
change_password(user_id, passwords[i])
I don't know why in the first code example, it handles the 429 errors on its own, but not with the second one.
Thank you!