I’ve got a Python script pulling WEM adherence data for our Pacific region. It runs every night to check agent schedule adherence. The script takes about 20 minutes to finish because of the volume.
I’m using the Genesys Cloud Python SDK. My understanding is that the PlatformClient handles token refresh automatically. I don’t see any explicit refresh calls in my code. But halfway through the run, the script crashes with a 401 Unauthorized error.
Here is the setup:
from platformclientv2 import PlatformClient
from platformclientv2.api.wem_api import WemApi
pc = PlatformClient()
pc.login_client_credentials(client_id, client_secret)
wem = WemApi(api_client=pc.api_client)
# This loop runs for 20+ minutes
for site in sites:
# Fetch adherence
resp = wem.get_wem_aggregation_query(query_id)
The error happens on the second or third batch of queries. The token was issued at start of script. It should be refreshing in background. Is there a setting I’m missing? Or does the SDK fail silently on refresh and I need to handle it manually?
platformclientv2.rest.ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Date': 'Wed, 12 Oct 2023 03:45:12 GMT'})
HTTP response body: {"message":"Unauthorized"}
I tried adding pc.api_client.refresh_token() but that method doesn’t exist. I’m stuck.