Closed bixb922 closed 9 months ago
@bixb922 Thanks for the report, I see now that I was computing the length before encoding and I wasn't aware that this could change with non-ascii characters. But this is now fixed in #782, if you find anything else, let me know 👍🏼
Works well for me now, both binary data and multibyte json, thanks a lot!
I'm sorry to bother again with aiohttp. Having an asyncio requests module with ssl support made me rewrite all code to take advantage of this excellent development. Thanks to you all!
When sending json data in a request with the json= parameter, and the json contains non-ascii characters (multi-byte characters), the Content-Length is less than it should be, and some information gets truncated.
This is with MicroPython v1.22.0 on 2023-12-27; Generic ESP32S3 module with Octal-SPIRAM with ESP32S3
I see this happening both with aiohttp and the requests (former urequests) module.
This is the test program:
The output is:
It seems that both modules use len(json as string) which counts characters, whereas Content-Length needs the length in bytes. And unlike CPython, MicroPython json.dumps converts to UTF-8, since there is no ensure_ascii parameter.