Skip to content

AWSIoTPythonSDK depends on ssl.wrap_socket() which was deprecated in Python 3.7 and removed in Python 3.12 #335

@bakerkj

Description

@bakerkj

Describe the bug

AWSIoTPythonSDK depends on ssl.wrap_socket() which was deprecated in python 3.7 and removed in python 3.12.

Below is an extract of a traceback that exposes the problem from the Home Assistant Plugin for the Navien Water Heater which uses this SDK (I believe the latest version on pypi 1.5.2). Home Assistant is just transitioning to Python 3.12 as noted here.

The full traceback can be found here nikshriv/hass_navien_water_heater#35

  File "/usr/local/lib/python3.12/site-packages/AWSIoTPythonSDK/MQTTLib.py", line 520, in connect
    return self._mqtt_core.connect(keepAliveIntervalSecond)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 196, in connect
    self.connect_async(keep_alive_sec, self._create_blocking_ack_callback(event))
  File "/usr/local/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 223, in connect_async
    raise e
  File "/usr/local/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 211, in connect_async
    rc = self._internal_async_client.connect(keep_alive_sec, ack_callback)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/internal/clients.py", line 125, in connect
    rc = self._paho_client.connect(host, port, keep_alive_sec)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 665, in connect
    return self.reconnect()
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 800, in reconnect
    rawSSL = ssl.wrap_socket(sock, ca_certs=self._tls_ca_certs, cert_reqs=ssl.CERT_REQUIRED)  # Add server certificate verification
             ^^^^^^^^^^^^^^^
AttributeError: module 'ssl' has no attribute 'wrap_socket'

Expected Behavior

The library works in python 3.12.

Current Behavior

The library fails to load with the above traceback in python 3.12.

Possible Solution

As noted here in the python 3.7 release notes:

ssl.wrap_socket() is deprecated. Use ssl.SSLContext.wrap_socket() instead.

Additional Information/Context

No response

SDK version used

1.5.2

Environment details (OS name and version, etc.)

Home Assistant 2024.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestA feature should be added or improved.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions