Legacy Dev Forum Posts

 View Only

Sign Up

PureCloudPlatformClientV2 urllib3 error

  • 1.  PureCloudPlatformClientV2 urllib3 error

    Posted 06-05-2025 18:09

    Yubin | 2023-10-17 08:19:13 UTC | #1

    Hi all

    I use PureCloudPlatformClientV2 sdk to execute getauthorizationdivisionspermittedpagedme, but an error was reported. I don't know how to solve this problem.

    File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connection.py", line 158, in _new_conn
        conn = connection.create_connection(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\connection.py", line 57, in create_connection
        for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\socket.py", line 962, in getaddrinfo
        for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    socket.gaierror: [Errno 11001] getaddrinfo failed
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 597, in urlopen
        httplib_response = self._make_request(conn, method, url,
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
        self._validate_conn(conn)
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
        conn.connect()
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connection.py", line 301, in connect
        conn = self._new_conn()
               ^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connection.py", line 167, in _new_conn
        raise NewConnectionError(
    urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x0000020064035490>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\workData\tools\cXcode\genesys-setup\src\genesys_flows.py", line 1016, in <module>
        download(configDir,flowType,nameList,keywordList)
      File "C:\workData\tools\cXcode\genesys-setup\src\genesys_flows.py", line 188, in download
        searchCls = SearchCls(mainCredential,credential)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\workData\tools\cXcode\genesys-setup\src\utils\search_utils.py", line 28, in wrapper
        instances[key] = cls(*args, **kwargs)
                         ^^^^^^^^^^^^^^^^^^^^
      File "C:\workData\tools\cXcode\genesys-setup\src\utils\search_utils.py", line 45, in __init__
        self.apiClient = self.getApiClient()
                         ^^^^^^^^^^^^^^^^^^^
      File "C:\workData\tools\cXcode\genesys-setup-script\src\utils\search_utils.py", line 51, in getApiClient
        apiClient = apiClient.get_client_credentials_token(self.cloudClientId, self.cloudClientSecret)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\PureCloudPlatformClientV2\api_client.py", line 126, in get_client_credentials_token
        response = self.request("POST", url,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\PureCloudPlatformClientV2\api_client.py", line 565, in request
        return self.rest_client.POST(url,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\PureCloudPlatformClientV2\rest.py", line 225, in POST
        return self.request("POST", url,
               ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\PureCloudPlatformClientV2\rest.py", line 168, in request
        r = self.pool_manager.request(method, url,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\request.py", line 70, in request
        return self.request_encode_body(method, url, fields=fields,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\request.py", line 150, in request_encode_body
        return self.urlopen(method, url, **extra_kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\poolmanager.py", line 324, in urlopen
        response = conn.urlopen(method, u.request_uri, **kw)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 663, in urlopen
        return self.urlopen(method, url, body, headers, retries,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 663, in urlopen
        return self.urlopen(method, url, body, headers, retries,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 663, in urlopen
        return self.urlopen(method, url, body, headers, retries,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      [Previous line repeated 7 more times]
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 637, in urlopen
        retries = retries.increment(method, url, error=e, _pool=self,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\yubin\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\retry.py", line 399, in increment
        raise MaxRetryError(_pool, url, error or ResponseError(cause))
    urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.mypurecloud.jp"', port=443): Max retries exceeded with url: /oauth/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000020064035490>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
    PS C:\workData\tools\cXcode\genesys-setup\src>

    Declan_ginty | 2023-10-17 08:31:19 UTC | #2

    Hi,

    Would you be able to send your code(with sensitive information redacted) also?

    Thanks, Declan


    Yubin | 2023-10-17 08:41:08 UTC | #3

    Hi , This is my test code.

    SearchCls.py

    import PureCloudPlatformClientV2
    import sys
    sys.path.append("..")
    from utils.logger_utils import LoggerWrapper
    from conf.config import GenesysCloudConfig
    from PureCloudPlatformClientV2.rest import ApiException
    from PureCloudPlatformClientV2.api_client import ApiClient
    from PureCloudPlatformClientV2.models import ResponseQueryRequest, ResponseFilter
    
    def singleton(cls):
        instances = {}
    
        def wrapper(*args, **kwargs):
            
            key = (cls, args, tuple(kwargs.items()))
            if key not in instances:
                instances[key] = cls(*args, **kwargs)
            return instances[key]
    
        return wrapper
    
    @singleton
    class SearchCls:
    
        def __init__(self, mainCredential = None,credential = None):
        
            self.cloudHost = "https://api.mypurecloud.jp"
            self.cloudClientId = <clientId>
            self.cloudClientSecret = <secret>
            self.apiClient = self.getApiClient()
    
        def getApiClient(self):
           
            apiClient = ApiClient(self.cloudHost)
            
            apiClient = apiClient.get_client_credentials_token(self.cloudClientId, self.cloudClientSecret)
            
            return apiClient
        
        # searchAllDivisions
        def searchAllDivisions(self, permission='directory:user:add', pageNumber=1, pageSize=9999):
            # apiClient = self.getApiClient()
            apiInstance = PureCloudPlatformClientV2.AuthorizationApi(self.apiClient)
            try:
                apiResponse = apiInstance.get_authorization_divisionspermitted_paged_me(
                    permission, page_number=pageNumber, page_size=pageSize)
                total = apiResponse.total
                if total > 0:
                    name = apiResponse.entities[0].name
                    id = apiResponse.entities[0].id
                    return {'res': True, 'name': name, 'id': id}
                else:
                    return {'res': False, 'name': '', 'id': ''}
            except ApiException as e:
                LoggerWrapper.error("Exception when calling UsersApi->get_authorization_divisionspermitted_paged_me: %s\n" % e)
                return {'res': False, 'name': '', 'id': ''}

    main.py

    
            searchCls = SearchCls()
            divisionResult = searchCls.searchAllDivisions()

    Yubin | 2023-10-18 06:14:38 UTC | #4

    Yubin, post:3, topic:22573
    Hi , This is my test code.

    SearchCls.py

    import PureCloudPlatformClientV2
    import sys
    sys.path.append("..")
    from utils.logger

    Hi , This is my test code.

    SearchCls.py

    import PureCloudPlatformClientV2
    import sys
    sys.path.append("..")
    from utils.logger_utils import LoggerWrapper
    from conf.config import GenesysCloudConfig
    from PureCloudPlatformClientV2.rest import ApiException
    from PureCloudPlatformClientV2.api_client import ApiClient
    from PureCloudPlatformClientV2.models import ResponseQueryRequest, ResponseFilter
    
    def singleton(cls):
        instances = {}
    
        def wrapper(*args, **kwargs):
            
            key = (cls, args, tuple(kwargs.items()))
            if key not in instances:
                instances[key] = cls(*args, **kwargs)
            return instances[key]
    
        return wrapper
    
    @singleton
    class SearchCls:
    
        def __init__(self, mainCredential = None,credential = None):
        
            self.cloudHost = "https://api.mypurecloud.jp"
            self.cloudClientId = <clientId>
            self.cloudClientSecret = <secret>
            self.apiClient = self.getApiClient()
    
        def getApiClient(self):
           
            apiClient = ApiClient(self.cloudHost)
            
            apiClient = apiClient.get_client_credentials_token(self.cloudClientId, self.cloudClientSecret)
            
            return apiClient
        
        # searchAllDivisions
        def searchAllDivisions(self, permission='directory:user:add', pageNumber=1, pageSize=9999):
            # apiClient = self.getApiClient()
            apiInstance = PureCloudPlatformClientV2.AuthorizationApi(self.apiClient)
            try:
                apiResponse = apiInstance.get_authorization_divisionspermitted_paged_me(
                    permission, page_number=pageNumber, page_size=pageSize)
                total = apiResponse.total
                if total > 0:
                    name = apiResponse.entities[0].name
                    id = apiResponse.entities[0].id
                    return {'res': True, 'name': name, 'id': id}
                else:
                    return {'res': False, 'name': '', 'id': ''}
            except ApiException as e:
                LoggerWrapper.error("Exception when calling UsersApi->get_authorization_divisionspermitted_paged_me: %s\n" % e)
                return {'res': False, 'name': '', 'id': ''}

    main.py

            searchCls = SearchCls()
            divisionResult = searchCls.searchAllDivisions()

    Declan_ginty | 2023-10-18 16:49:20 UTC | #5

    Hi,

    I had to modify your code slightly but I was able to get it to run, here's my version:

    import os
    import PureCloudPlatformClientV2
    import sys
    from PureCloudPlatformClientV2.rest import ApiException
    from PureCloudPlatformClientV2.api_client import ApiClient
    from PureCloudPlatformClientV2.models import ResponseQueryRequest, ResponseFilter
    sys.path.append("..")
    
    def singleton(cls):
        instances = {}
    
        def wrapper(*args, **kwargs):
            key = (cls, args, tuple(kwargs.items()))
            if key not in instances:
                instances[key] = cls(*args, **kwargs)
            return instances[key]
    
        return wrapper
    
    
    @singleton
    class SearchCls:
    
        def __init__(self, mainCredential=None, credential=None):
    
            self.cloudHost = "https://api.mypurecloud.com"
            self.cloudClientId = os.environ['PURECLOUD_CLIENT_ID']
            self.cloudClientSecret = os.environ['PURECLOUD_CLIENT_SECRET']
            self.apiClient = self.getApiClient()
    
        def getApiClient(self):
            apiClient = ApiClient(self.cloudHost)
    
            apiClient = apiClient.get_client_credentials_token(self.cloudClientId, self.cloudClientSecret)
    
            return apiClient
    
        # searchAllDivisions
        def searchAllDivisions(self, permission='directory:user:add', pageNumber=1, pageSize=9999):
            apiInstance = PureCloudPlatformClientV2.AuthorizationApi(self.apiClient)
            try:
                apiResponse = apiInstance.get_authorization_divisionspermitted_paged_me(permission, page_number=pageNumber, page_size=pageSize)
                total = apiResponse.total
                if total > 0:
                    name = apiResponse.entities[0].name
                    id = apiResponse.entities[0].id
                    return {'res': True, 'name': name, 'id': id}
                else:
                    return {'res': False, 'name': '', 'id': ''}
            except ApiException as e:
                print("Exception when calling UsersApi->get_authorization_divisionspermitted_paged_me: %s\n" % e)
                return {'res': False, 'name': '', 'id': ''}
    
    
    searchCls = SearchCls()
    divisionResult = searchCls.searchAllDivisions()
    print(divisionResult)

    The main change I had to make was removing these imports:

    from utils.logger_utils import LoggerWrapper
    from conf.config import GenesysCloudConfig

    I am no expert with python but it seems the problem might becoming from one of those imports.

    Regards, Declan


    system | 2023-11-18 16:50:05 UTC | #6

    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: 22573