Bytes and Strings, oh my

So, I recently ran into an issue with an Python API that still expects str for a byte-based method in Python3… presumably whoever wrote the wrapper has not updated it to reflect the fact that bytes and str are no longer interchangeable in 3.

The sorry saga is recorded below, but the TLDR is this

‘iso8859_15’ and ‘mbcs’ are python codecs which handle all the byte values in the range 0-255. So if you have a bunch of bytes and some idiot Python3 code still wants ‘strings’, you can do

  bytes.decode('iso8859_15')

and the data won’t be changed except for looking like str instead of bytes