Thread safe https post

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Cosystick
Posts: 1
Joined: Wed Jun 01, 2022 8:35 am

Thread safe https post

Post by Cosystick » Wed Jun 01, 2022 10:18 am

Hello fellow Hardware-tinkerers!
I am using asyncio.start_server to serve html for monitoring a thermometer and to administer temp triggers and notification settings.
I have a Wemos D1 Mini (esp8266) board.

Serving the html works, reading the thermometer using onewire works, saving settings to local storage works.

When I use asyncio to do a asyncio.post to the pushbullet api, using HTTPS.
I can't seem to get anything but no response or 400 Bad Request. I have seen some mentioning of asyncio not working with SSL, but then some where the author says it's working.

I have tried using a version of arequest.py I found while googling, urequest is blocking and isn't working, I have tried using a "lib" called http_client and I have tried all manner of other different libs.

I can't seem to find any that doesn't end up with a bad request or none response.

What I want to do, is an async post, with headers and json body to https.

Does anyone have any ideas? Does anyone have the source code to the latest version of arequest.py?

KJM
Posts: 158
Joined: Sun Nov 18, 2018 10:53 pm
Location: Sydney AU

Re: Thread safe https post

Post by KJM » Thu Jun 02, 2022 5:34 am

I'm not familiar with arequest.py but urequests can do headers+json if suitably primed https://stackoverflow.com/questions/624 ... n-language

Re thread safe usage. I too read a lot of stuff about asyncio/ssl compatibility. I ended up calling urequests from a timed out def as a separate thread. If the urequests thread stalls the calling def times out & the main program is free to continue after the timeout.

Post Reply