← index #5929Issue #374
Related · medium · value 1.480
QUERY · ISSUE

MQTT to AWS IoT Core fails with mbedtls_ssl_handshake_error

openby Aish-Gitopened 2020-04-16updated 2023-05-15
port-esp32

mbedtls_ssl_handshake error: -2880
I (14912) wifi:Traceback (most recent call last):
File "main.py", line 99, in <module>
File "main.py", line 96, in <module>
File "main.py", line 69, in mqtt
File "umqtt/simple.py", line 61, in connect
OSError: [Errno 5] EIO

Fails on the latest firmware but works on any of the 2019 builds - tried it with esp32-idf3-20191220-v1.12.bin and it works but needed BLE and hence upgraded to 2020 versions and fails on all the March/April releases.

CANDIDATE · ISSUE

urllib.urequest.urlopen fails with mbedtls_ssl_handshake error on ESP32

closedby konekohanaopened 2020-03-14updated 2020-03-26

I'm running into problems when trying to make an HTTP request to one particular page using urllib.urequest installed by upip in micropython (version micropython/micropython@eae495a71 with russhughes/st7789_mpy@ff343dc compiled in):

>>> from urllib.urequest import urlopen
>>> res = urlopen('https://aladinonline.androworks.org/')
mbedtls_ssl_handshake error: -4290
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/urllib/urequest.py", line 30, in urlopen
OSError: [Errno 5] EIO

The WiFi connection seems to be working because I can connect to other pages just fine, I didn't find a single page other than this one that would fail with the same error. I tried looking for the -4290 error code in mbedtls documentation, but I couldn't find anything.

The big picture here is that I'm trying to build a tiny weather station with the TTGO T-Display board. The page that I'm trying to connect here offers a very convenient API for data from a particular atmospheric model used for the weather forecast in Europe (ALADIN). My initial goal is to make a request to the API, store the response (which contains a forecast for the next two days) and show some information from it on the board's display. This is my first micropython project though and I have no clue how to debug the issue further. Any ideas?

4 comments
konekohana · 2020-03-16

I tried looking into urlopen code, and I managed to replicate the issue using just micropython library, this time using vanilla micropython version v1.12-256-geae495a71 from the site's download page, but I'm unsure what to do next. The following fails with the same error as the urlopen call, suggesting this might be a bug in micropython itself, not in micropython-lib's implementation of urllib:

>>> s = usocket.socket()
>>> s.connect(('185.8.236.214', 443))
>>> s = ussl.wrap_socket(s, server_hostname="aladinonline.androworks.org")
mbedtls_ssl_handshake error: -4290
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 5] EIO

The micropython documentation, however, doesn't say anything about the server_hostname parameter of ussl.wrap_socket function. If I omit the parameter, the connection works fine:

>>> s = usocket.socket()
>>> s.connect(('185.8.236.214', 443))
>>> s = ussl.wrap_socket(s)
>>> s.write(b"GET / HTTP/1.0\r\nHost: aladinonline.androworks.org\r\n\r\n")
53
>>> s.readline()
b'HTTP/1.1 200 OK\r\n'

but since the parameter isn't documented, I don't know what other side effects this change has. Is this a micropython bug and should I open an issue there (and close this one), or does it belong here?

mardigras2020 · 2020-03-24

Hi - had the same issue an i downgraded the ESP Firmware to esp32-idf3-20191220-v1.12.bin
after flashing the board with the stable release - it worked for me.

konekohana · 2020-03-24

Oh, you're right @mardigras2020, it does work with esp32-idf3-20191220-v1.12.bin. I didn't even realise the other one was a nightly version when I downloaded it, that's why I didn't try it with a stable one. Now it really seems like a bug in micropython itself. I'll try to find out which commit introduced it, open an issue in the other repository and close this one.

konekohana · 2020-03-26

Closing the issue as this seems to be a micropython bug after all.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied