Skip to content Skip to sidebar Skip to footer

How To Fix 'UnicodeDecodeError: 'utf-8' Codec Can't Decode Byte' When Using Python C Extensions?

Given the following file bug.txt: event 'øat' not handled I wrote the following Python C Extensions on the file fastfilewrapper.cpp #include #include

Solution 1:

If you want to have 'replace' error handling semantic you should do it on the C side like so and return it to the python side:

return PyUnicode_DecodeUTF8(retval.c_str(), retval.size(), "replace");

This will give in our case sth like:

Hello, world!
retval event "?at" not handled
iterable event "�at" not handled

Post a Comment for "How To Fix 'UnicodeDecodeError: 'utf-8' Codec Can't Decode Byte' When Using Python C Extensions?"