vshymanskyy / blynk-library-python

Blynk library for Python. Works with Python 2, Python 3, MicroPython.
https://blynk.io/
MIT License
281 stars 97 forks source link

Fix SSL context creation for MicroPython v1.23.0 #82

Open U-1F992 opened 2 weeks ago

U-1F992 commented 2 weeks ago

Starting with MicroPython v1.23.0, the ussl module is no longer provided and only the ssl module is available (at least on the rp2 port).

Therefore, l.235 in BlynkLib.py falls back to l.238 and AttributeError is raised.

MicroPython v1.23.0 on 2024-06-02; Raspberry Pi Pico W with RP2040

Type "help()" for more information.

>>> import ussl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'ussl'
>>> import ssl
>>> dir(ssl)
['__class__', '__name__', 'CERT_NONE', 'CERT_OPTIONAL', 'CERT_REQUIRED', 'MBEDTLS_VERSION', 'PROTOCOL_TLS_CLIENT', 'PROTOCOL_TLS_SERVER', 'SSLContext', '__dict__', '__file__', 'tls', 'wrap_socket', '__version__']
>>> ssl.create_default_context()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'create_default_context'

Instead of ssl.create_default_context(), we can use ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) to avoid the problem.