PaulerMladenA66553 | 2023-08-10 13:56:50 UTC | #1
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!
Jerome.Saint-Marc | 2023-08-10 14:48:18 UTC | #2
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 CLIENTID directly -> CLIENTID = 'qdsqsdqsd'
Regards,
PaulerMladenA66553 | 2023-08-10 17:18:57 UTC | #3
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 makerequest self.validateconn(conn) File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 1092, in validateconn conn.connect() File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connection.py", line 642, in connect sockandverified = sslwrapsocketandmatchhostname( File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connection.py", line 783, in sslwrapsocketandmatchhostname sslsock = sslwrapsocket( File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\util\ssl.py", line 469, in sslwrapsocket ssl_sock = sslwrapsocketimpl(sock, context, tlsintls, serverhostname) File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\util\ssl.py", line 513, in sslwrapsocketimpl return sslcontext.wrapsocket(sock, serverhostname=serverhostname) File "C:\Users\ah66553\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 513, in wrapsocket return self.sslsocketclass._create( File "C:\Users\ah66553\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1071, in create self.dohandshake() File "C:\Users\ah66553\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1342, in dohandshake self.sslobj.dohandshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATEVERIFYFAILED] 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.makerequest( File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\connectionpool.py", line 491, in makerequest raise newe urllib3.exceptions.SSLError: [SSL: CERTIFICATEVERIFYFAILED] 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\getnumberofonqueueagents.py", line 20, in <module> .getclientcredentialstoken(CLIENTID, CLIENTSECRET) File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\PureCloudPlatformClientV2\apiclient.py", line 126, in getclientcredentialstoken response = self.request("POST", url, File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\PureCloudPlatformClientV2\apiclient.py", line 565, in request return self.restclient.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.poolmanager.request(method, url, File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3_requestmethods.py", line 118, in request return self.requestencodebody( File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3_requestmethods.py", line 217, in requestencodebody return self.urlopen(method, url, *extrakw) File "C:\Users\ah66553\PycharmProjects\pythonProject\venv\lib\site-packages\urllib3\poolmanager.py", line 443, in urlopen response = conn.urlopen(method, u.requesturi, *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: CERTIFICATEVERIFYFAILED] certificate verify failed: unable to get local issuer certificate (ssl.c:997)')))
Declan_ginty | 2023-08-10 17:23:59 UTC | #4
Hi,
Could you show us your code where you are doing your authentication?
Regards, Declan
Jerome.Saint-Marc | 2023-08-10 17:25:42 UTC | #5
I'd suggest to follow Tim's suggestion in this older post: https://developer.genesys.cloud/forum/t/ssl-certification-problem/6515 "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."
PaulerMladenA66553 | 2023-08-10 17:53:02 UTC | #6
PaulerMladenA66553, post:1, topic:21456
(https://developer.genesys.cloud/analyticsdatamanagement/analytics/observation/number-of-agents-on-queue-guide)
Hi Declan, I copied the code from here: https://developer.genesys.cloud/analyticsdatamanagement/analytics/observation/number-of-agents-on-queue-guide
PaulerMladenA66553 | 2023-08-10 17:54:18 UTC | #7
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.
system | 2023-09-10 17:55:01 UTC | #8
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 21456