Is there documentation anywhere detailing the differences in decode() and how it has changed between 3.14 and 3.15?
I have some code which deals with html Post “multipart/form-data” and as far as I recall worked fine in 3.14. However with 3.15.0rc2 this now causes utf-8 can't decode byte 0xff in pos 262.
Could it perhaps be that 3.14 used to automatically detect the encoding but 3.15 now doesn’t do that but defaults to utf-8 instead?
It never auto-detected the encoding. It always used the system locale before Python 3.15. One can use encoding='locale' since Python 3.10 to keep the old behavior.
If this is data then it should remain as bytes rather than being decoded into str. .decode is typically incorrect for a raw bytes stream. This code as you’ve explained it would crash when run on a platform with a UTF-8 locale regardless of Python version.
Incoming stream from wsgi_input.read is, as far as I can determine, bytes. However that needs to be split out into sections delimited by content_type.boundary and needs to have last occurrence of “–” removed (after right stripping /r/n). Can’t see how I can do this while the object remains as bytes.
What I tried to post was hyphen-hyphen, don’t know how I am supposed to do that.
If post_data is left as bytes it errors in:
if post_data.rstrip().endswith("--"):
with
endswith first arg must be bytes or a tuple of bytes, not str
Have to admit I didn’t know that I could use things like .rstrip() / endswith() / .split() with a bytes object. Seems I just need to add .encode() to other parameters like this:
if post_data.rstrip().endswith("--".encode()):
However I question whether the post_data is really bytes or is actually encoded in some way. I have just viewed that file in notepad and it is totally different to what I see printed in the Python terminal when I print(post)data.
Many thanks @HexDecimal & @Standre, changed to bytes type all the way through the code, took a while, but now fully working. File from html post_data saves correctly.
Just got the type-hints for these modifications to change now.