[Fixed]-UnicodeDecodeError in socket.sendall with Django

1👍

0x98 is not a valid ASCII character. Where does that character come from?

As a workaround, try using ‘latin1’ codec. (Latin-1 has a valid code point for each of the 256 possible byte values so, even though the text you send may not make sense at the far end, you can successfully encode and decode all byte values using it.)

Something like this:

sock.sendall(msg + astr.encode('latin1'))

More generally, you’ll need to discover where the 0x98 character comes from and determine what is the proper codec to use in transmitting it to the server.

Leave a comment