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
Lir10
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)

produces:

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

jamesb
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 pushingbox.com as described here: https://www.hackster.io/detox/transmit- ... ets-8fc617

Capstan
Posts: 117
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?

derp
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'
    b'Host: www.google.com\r\n'
    b'\r\n'
)

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

s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.connect(addr)
s2 = ssl.wrap_socket(s1)
s2.write(request)
while True:
    r = s2.read(128)
    if not r:
        break
    print(r)
Replacing two lines

Code: Select all

s1.connect(addr)
s2 = ssl.wrap_socket(s1)
with

Code: Select all

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

Post Reply