Getting KeyError when trying to run the sample "get_number_of_onqueue_agents.py"

Hi everyone,

New to using the Python SDK, so I am probably missing something simple here. I tried to use the sample code provided by Genesys to pull a number of on-queue agents from a queue (https://developer.genesys.cloud/analyticsdatamanagement/analytics/observation/number-of-agents-on-queue-guide). However I get an error "KeyError(key) from None".

(Of course I entered my own OAuth client ID and secret, known to work in other cases.)

Any ideas?

Thanks!

Hello,

I can't read your screenshot but I think you have misunderstood setting of CLIENT_ID (and other vars).
os.environ in python is to retrieve environment variables (in your computer/OS) -> trying to extract the value of a variable of name corresponding to what you have put in os.environ[your environment variable name].

Just set CLIENT_ID directly -> CLIENT_ID = 'qdsqsdqsd'

Regards,

Hey Jerome,

Thanks for responding. That makes sense now that you say it. So, I have corrected that, but now I am getting (I think) some sort of an SSL error. Below is the whole printout (it is a lot)...


  • Python3 Get Number of On-Queue Agents using Genesys Cloud SDK -

Traceback (most recent call last):
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request
self._validate_conn(conn)
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 1092, in _validate_conn
conn.connect()
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connection.py", line 642, in connect
sock_and_verified = _ssl_wrap_socket_and_match_hostname(
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connection.py", line 783, in ssl_wrap_socket_and_match_hostname
ssl_sock = ssl_wrap_socket(
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\util\ssl
.py", line 469, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\util\ssl
.py", line 513, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "C:\Users\ah66553\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 513, in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\ah66553\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1071, in _create
self.do_handshake()
File "C:\Users\ah66553\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1342, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 790, in urlopen
response = self._make_request(
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 491, in _make_request
raise new_e
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\ah66553\PycharmProjects\pythonProject\Genesys\get_number_of_onqueue_agents.py", line 20, in
.get_client_credentials_token(CLIENT_ID, CLIENT_SECRET)
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\PureCloudPlatformClientV2\api_client.py", line 126, in get_client_credentials_token
response = self.request("POST", url,
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\PureCloudPlatformClientV2\api_client.py", line 565, in request
return self.rest_client.POST(url,
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\PureCloudPlatformClientV2\rest.py", line 225, in POST
return self.request("POST", url,
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\PureCloudPlatformClientV2\rest.py", line 168, in request
r = self.pool_manager.request(method, url,
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3_request_methods.py", line 118, in request
return self.request_encode_body(
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3_request_methods.py", line 217, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\poolmanager.py", line 443, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 874, in urlopen
return self.urlopen(
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 874, in urlopen
return self.urlopen(
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 874, in urlopen
return self.urlopen(
[Previous line repeated 7 more times]
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 844, in urlopen
retries = retries.increment(
File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\util\retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.mypurecloud.com', port=443): Max retries exceeded with url: /oauth/token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))

Hi,

Could you show us your code where you are doing your authentication?

Regards,
Declan

I'd suggest to follow Tim's suggestion in this older post: SSL Certification Problem
"This error comes from Python's internal code when it fails to verify the SSL cert. You will need to configure your python environment/app to handle certificates appropriately. Doing an online search for python CERTIFICATE_VERIFY_FAILED should yield a wealth of information about this issue with Python and how to fix it."

Hi Declan, I copied the code from here: https://developer.genesys.cloud/analyticsdatamanagement/analytics/observation/number-of-agents-on-queue-guide

Thanks Jerome,

I was able to resolve by following these instructions:

One possible solution is to instruct Python to use your Windows Certificate Store instead of the built-in store in the certifi package. You can do that by installing python-certifi-win32:

pip install python-certifi-win32

Python in then using the same certificates as your browsers do.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.