micropython / micropython-lib

Core Python libraries ported to MicroPython
Other
2.37k stars 993 forks source link

ussl: AttributeError: 'module' object has no attribute 'CERT_REQUIRED' #249

Open SergeSpinoza opened 6 years ago

SergeSpinoza commented 6 years ago

Hi! I need to connect to MQTT via SSL/TLS.

When I try to connect to MQTT without SSL - allready is good. When I try to connect with ssl like this:

client = MQTTClient(CONFIG['CLIENT_ID'], CONFIG['MQTT_BROKER'], user=CONFIG['USER'], password=CONFIG['PASSWORD'], port=CONFIG['PORT'], ssl = True, ssl_params = {"cert_reqs":ussl.CERT_REQUIRED, "ca_certs":"/flash/cacert.pem"})

I have a error:

AttributeError: 'module' object has no attribute 'CERT_REQUIRED'

It's strange, because in official doc ([http://micropython.org/resources/docs/en/latest/wipy/library/ussl.html]) says that ussl.CERT_REQUIRED must be work, but it's not work =(

What could be the problem?

manningt commented 5 years ago

More info can be found in issue 2781

Swington commented 5 years ago

@SergeSpinoza I think that CERT_REQUIRED is not actually in 'ussl' library, but in 'ssl' library, which would be 'micropython-ssl' for upip. After importing 'micropython-ssl' onto esp8266 and importing CERTREQUIRED from 'ssl' this problem disappeared for me. Actually if you look in the code of 'ssl' module in micropython-lib repo, these static values (CERT*)are created while importing 'ssl' module. But even if you'll fix that the ssl will not work on esp8266, cause of another error, which the @manningt linked to.