You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Need solution for asyncio SSL/TLS connections #8647
How to open a SSL or TLS connection using uasyncio?
I am tryign to port a CPython project onto Micropython.
In CPython asyncio, we could open a SSL connection easily by using ssl argument in asyncio.open_connection() method.
When I am trying to use uasyncio.open_connection(..., ssl=True), it raises an exception saying that there's no ssl argument. We can confirm it on the doc page here.
Then I try to use ssl module to warp the socket in StreamWriter.get_extra_info("socket")(I never test this, I don't know whether this would work, just have a try), but I cannot get the "raw" socket of this connection, because function uasyncio.Stream.get_extra_info only accept "peername" as a param, no support for "socket". We can check it here.
If there's a method to open an SSL/TLS connection by using uasyncio? I really want to use asyncio because I think that is the best part of python language.
I ran into this last week and also implemented my own asyncio friendly implementation. My version is optimized for my application, but asyncio ssl open_connection is surely something that would be apprecaited by future travelers.
I will also agree asyncio is my favorite part of python language! Game changer for microcontroller dev.
Activity
[-]Module uasyncio is lack of support for SSL/TLS support.[/-][+]Need solution for asyncio SSL/TLS connections[/+]RuofengX commentedon May 10, 2022
Here is the code https://github.com/RuofengX/uPyxy/blob/c3772838be208056282e01ed0d3f8da0c8fa4de8/main/lib/client.py#L103
peterhinch commentedon May 10, 2022
You might like to look at mqtt_as which uses nonblocking sockets and works over TLS.
hyx0329 commentedon May 10, 2022
I implemented a workaround for my project here. It's basically a custom connection maker based on the original one.
stephanelsmith commentedon May 18, 2022
I ran into this last week and also implemented my own asyncio friendly implementation. My version is optimized for my application, but asyncio ssl open_connection is surely something that would be apprecaited by future travelers.
I will also agree asyncio is my favorite part of python language! Game changer for microcontroller dev.
dpgeorge commentedon Dec 14, 2023
Asyncio SSL server and client are now supported.