← index #18531Issue #168
Related · high · value 1.634
QUERY · ISSUE

Add function 'settimeout' to class SSLSocket

openby magnus-0opened 2025-12-08updated 2026-03-09
enhancementextmod

Description

After wrapping a micropython socket to get a SSLSocket, the function 'settimeout()' fails, reporting that feature doesn't exist (same with 'gettimeout()'). Interestingly though, the 'setblocking()' function does exist and seemingly work.

AttributeError: 'SSLSocket' object has no attribute 'settimeout'

Code Size

Irrelevant (the feature was most likely already supposed to be there but overlooked?)

Implementation

I hope the MicroPython maintainers or community will implement this feature

Code of Conduct

Yes, I agree

[MODERATOR: This topic may have been better posted under 'micropython-lib' instead of plain micropython...

CANDIDATE · ISSUE

umqtt.simple using ssl: check_msg() throws NotImplementedError

closedby stlehmannopened 2017-04-21updated 2024-08-27

The check_msg() function uses socket.setblocking() to check for pending messages without blocking. While working fine with normal sockets this leads to an NotImplementedError when used with a ssl connection.

To create a ssl connection the ussl.wrap_socket() function is used which returns a ussl._SSLSocket object. For the _SSLSocket class there exists only a method stub for setblocking() that throws a NotImplementedError. So basically the _SSLSocket.setblocking() method needs to be implemented in the ussl library for this to work.

10 comments
pfalcon · 2017-04-21

So basically the _SSLSocket.setblocking() method needs to be implemented in the ussl library for this to work.

No, of course no. You're staying in you car ahead of big-big pit on the street with a warning sign in front of it. And now you're saying that to pass the street you need to remove this warning sign.

stlehmann · 2017-04-21

Ok, I might have missed something here but can't see what. What is the sign warning me from?

pfalcon · 2017-04-21

That non-blocking I/O support for SSL sockets is not implemented, and it's pretty complex thing ("big-big pit"), or otherwise it would have been implemented long ago.

stlehmann · 2017-04-21

I see...so this is a more complex topic... But is there a workaround?
I need to send regular ping requests to the mosquitto server in order to keep the connection alive. I can't do that with a blocking socket. At the moment all I can do is drop the ssl encryption and use a normal socket.

SlowBro904 · 2017-07-24

MrLeeh could you fork a new thread and send pings? I'm very new at this so apologies if that sounds like an ignorant question, but it seems to me that would work.

stlehmann · 2017-07-24

@SlowBro904 with full-grown Python this would be possible I guess. But afaik there is no threading implemented in Micropython, yet.

SlowBro904 · 2017-07-24

Threading is usable in Pycom's uPy, and I have successfully flashed that to
a standard WROOM-32. Theirs is open source.

(It's not completely usable in that state, one must also alter the pins in
a csv file and recompile, but I wanted to see it done as a proof of
concept. Also their threading is not complete, with no way to exit a thread
from the outside. I hacked a workaround using a global variable as a
flag and it works.)

SlowBro904 · 2017-07-24

Oh, and I found this. You /might/ have threading in your implementation after all. Go try it.
https://forum.micropython.org/viewtopic.php?t=1864

chtinnes · 2019-10-22

As a workaround, check_msg might be modified to use polling:

    def check_msg(self, timeout):
        poller = uselect.poll()
        poller.register(self.sock, uselect.POLLIN)
        res = poller.poll(timeout)  # time in milliseconds
        if not res:
            return None
        return self.wait_msg()
jonnor · 2024-08-25

mqtt.simple should work with SSL for many years now. If there are issues, please re-open with details on how to reproduce.

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