Decoding error receiving messages

I’m going to add that I suspect you’ve received exactly 2048 bytes, and that the last X bytes are a partial code point.
As an example, © under UTF-8 is C6A9. And if the final byte in what you just received is C6?
b’\xc6’.decode(‘utf-8’)
UnicodeDecodeError: ‘utf8’ codex can’t decode byte 0xc6 in position 0: unexpected end of data

You need to use something like the codec module’s incremental decoder so it can join one socket read to another and recognize a stub code point split between recv calls.

1 Like