This is a coding error - therefore, if it is a Unicode string, this should fix it:
text.encode("windows-1252").decode("utf-8")
If this is a simple line, you will need an additional step:
text.decode("utf-8").encode("windows-1252").decode("utf-8")
Both of them will give you a Unicode string.
By the way, to find out how due to encoding problems due to encoding problems some text, you can use chardet :
>>> import chardet >>> chardet.detect(u"And the Hipรขโฌโขs coming, too") {'confidence': 0.5, 'encoding': 'windows-1252'}
source share