I have a python module that I need to adapt from py2 to py3. The problem is, it accepts an std::string from a C++ module as part of a struct, which was readable in py2 since the default py2 string type was bytes
. When trying to launch it with py3, however, it tries to interpret that string with utf8 whenever I try to do anything with it.
Basically, the message deserializer is expecting a bytes-like object, but is getting a normal, albeit unreadable, string instead.
For instance, this doesn't work:
msg_raw_data = bytes(msg.raw_data, encoding='latin-1')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 4: invalid start byte
Unfortunately, I cannot change the way the string comes into the module, but I don't need to read that string as an actual valid string - I just need to extract a bytes
object from it without discarding any values. Is there a way to do that?