Genesys Cloud - Developer Community!

 View Only

Sign Up

Getting "Cannot create a client socket with a PROTOCOL_TLS_SERVER context (_ssl.c:806)" when using Python SDK

  • 1.  Getting "Cannot create a client socket with a PROTOCOL_TLS_SERVER context (_ssl.c:806)" when using Python SDK

    Posted 05-06-2025 13:23

    Hi,

    I have been using Python SDK for several years now. After updating to PureCloudPlatformClientV2 package 227.0.0, my code suddenly stopped working.

    My code uses Client Credentials Grant and I also need to set the API environment to EU-West-1 as per what my Org is located. This is what I have been using successfully for several years.

    region = PureCloudPlatformClientV2.PureCloudRegionHosts.eu_west_1
    PureCloudPlatformClientV2.configuration.host = region.get_api_host()
    #Here config_client_id and config_client_secret store my OAuth client details which I read previously from another file
    api_client = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(config_client_id, config_client_secret)
    #This is a sample API class initialization
    telephony_api_instance = PureCloudPlatformClientV2.TelephonyProvidersEdgeApi(api_client)
    Usually this code would work perfectly. But now I am getting the below error

    Traceback (most recent call last):
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 466, in _make_request
        self._validate_conn(conn)
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 1095, in _validate_conn
        conn.connect()
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connection.py", line 652, in connect
        sock_and_verified = _ssl_wrap_socket_and_match_hostname(
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connection.py", line 805, in _ssl_wrap_socket_and_match_hostname
        ssl_sock = ssl_wrap_socket(
                   ^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\util\ssl_.py", line 465, in ssl_wrap_socket
        ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\util\ssl_.py", line 509, in _ssl_wrap_socket_impl
        return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\ssl.py", line 455, in wrap_socket
        return self.sslsocket_class._create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\Python312\Lib\ssl.py", line 1033, in _create
        self._sslobj = self._context._wrap_socket(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ssl.SSLError: Cannot create a client socket with a PROTOCOL_TLS_SERVER context (_ssl.c:806)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 789, in urlopen
        response = self._make_request(
                   ^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 490, in _make_request
        raise new_e
    urllib3.exceptions.SSLError: Cannot create a client socket with a PROTOCOL_TLS_SERVER context (_ssl.c:806)

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

    Traceback (most recent call last):
      File "c:\Soumik Work\Code\GenesysCloudTelephonyObjectsToolkit\get_All_DIDs_v1.py", line 52, in <module>
        api_client = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(config_client_id, config_client_secret)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\PureCloudPlatformClientV2\api_client.py", line 180, in get_client_credentials_token
        response = http_client.request(request_options)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\PureCloudPlatformClientV2\default_http_client.py", line 38, in request
        return self.rest_client.POST(config['url'],
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\PureCloudPlatformClientV2\rest.py", line 236, in POST
        return self.request("POST", url,
               ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\PureCloudPlatformClientV2\rest.py", line 179, in request
        r = self.pool_manager.request(method, url,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\_request_methods.py", line 144, in request
        return self.request_encode_body(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\_request_methods.py", line 279, in request_encode_body
        return self.urlopen(method, url, **extra_kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\poolmanager.py", line 443, in urlopen
        response = conn.urlopen(method, u.request_uri, **kw)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 873, in urlopen
        return self.urlopen(
               ^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 873, in urlopen
        return self.urlopen(
               ^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 873, in urlopen
        return self.urlopen(
               ^^^^^^^^^^^^^
      [Previous line repeated 7 more times]
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 843, in urlopen
        retries = retries.increment(
                  ^^^^^^^^^^^^^^^^^^
      File "C:\Users\609049066\AppData\Roaming\Python\Python312\site-packages\urllib3\util\retry.py", line 519, in increment
        raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.mypurecloud.ie', port=443): Max retries exceeded with url: /oauth/token (Caused by SSLError(SSLError(0, 'Cannot create a client socket with a PROTOCOL_TLS_SERVER context (_ssl.c:806)')))

    Has anything changed in Genesys? I don't believe this is an error because the SDK documentation provides the above code snippet.


    #PlatformSDK

    ------------------------------
    Soumik Biswas
    Responsible Delivery Lead
    BT Business
    ------------------------------