ssl_handshake_status: -256

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Posts: 1
Joined: Wed Jan 11, 2017 10:02 am

ssl_handshake_status: -256

Post by Lir10 » Wed Jan 11, 2017 10:05 am

Running the following code :

>>> import usocket as socket
>>> import ussl as ssl
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> ss = ssl.wrap_socket(s)


ssl_handshake_status: -256
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 5] EIO

Posts: 13
Joined: Tue Nov 29, 2016 3:31 am

Re: ssl_handshake_status: -256

Post by jamesb » Thu Jan 12, 2017 2:12 am

I get this response trying to post to Google sheets. Reading around, I think it's something to do with the ssl certificate size filling up memory. I'm looking for a solution to post to an intermediate non-secure API that can then forward on using ssl - appreciate any pointers. Maybe something like as described here: ... ets-8fc617

Posts: 115
Joined: Sun Jan 29, 2017 4:03 pm
Location: Texas, USA

Re: ssl_handshake_status: -256

Post by Capstan » Mon Jul 03, 2017 6:18 pm

Seeing a similar issue here. Does anyone have some working example code that demonstrates working SSL?

Posts: 3
Joined: Mon May 18, 2020 11:52 pm

Re: ssl_handshake_status: -256

Post by derp » Fri May 29, 2020 11:34 am

In the ESP8266 port, MicroPython uses the axtls library to do SSL. In axtls, SSL_ERROR_CONN_LOST is defined as -256. Also, EIO tells us that the error is related to input and/or output. So, making an educated guess, I think this is happening because ssl.wrap_socket expects s to be connected already, which you probably were not expecting, because in standard Python, s would not have to be connected already.

To confirm my hunch, I did something similar to you, but I added a s.connect statement before the ssl.wrap_socket call, and voila, it worked. Here is the successful code that I ran in my NodeMCU (ESP8266) MicroPython REPL:

Code: Select all

import socket
import ssl

request = (
    b'GET / HTTP/1.1\r\n'

addr = socket.getaddrinfo('', 443)[0][-1]

s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2 = ssl.wrap_socket(s1)
while True:
    r =
    if not r:
Replacing two lines

Code: Select all

s2 = ssl.wrap_socket(s1)

Code: Select all

s2 = ssl.wrap_socket(s1)
causes a failure similar the one described in the original post at the wrap_socket line. I think this confirms my hypothesis.

Post Reply