blynk-library-python icon indicating copy to clipboard operation
blynk-library-python copied to clipboard

Fix SSL context creation for MicroPython v1.23.0

Open u1f992 opened this issue 1 year ago • 1 comments

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.

u1f992 avatar Jun 17 '24 01:06 u1f992

I'm +1 on this pull request. After reading the error message and researching the documentation, I realised it was replaced with ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) . @vshymanskyy It would be great if you could merge this pull request, as a lot of people rely on this library (via YT tutorials).

Astrophsica avatar Feb 10 '25 03:02 Astrophsica