Try
text = unicode(text, encoding, "replace")
From the documentation :
'replace' causes Unicode characters, U + FFFD to be replaced, to replace input characters that cannot be decoded.
If you want to use "?"Unicode replacements instead of the official character, you can do
text = text.replace(u"\uFFFD", "?")
after converting to Unicode.
source
share