Page 1 of 1

ssl_handshake_status: -256

Posted: Wed Jan 11, 2017 10:05 am
by Lir10
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

Re: ssl_handshake_status: -256

Posted: Thu Jan 12, 2017 2:12 am
by jamesb
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

Re: ssl_handshake_status: -256

Posted: Mon Jul 03, 2017 6:18 pm
by Capstan
Seeing a similar issue here. Does anyone have some working example code that demonstrates working SSL?

Re: ssl_handshake_status: -256

Posted: Fri May 29, 2020 11:34 am
by derp
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.