It seems that you have separate bytes of the UTF-8 encoded string interpreted as Unicode code pages. You can "decode" your string from this strange form with:
p.name = ''.join(chr(ord(x)) for x in p.name)
or maybe
p.name = ''.join(chr(ord(x)) for x in p.name).decode('utf8')
One way to get your lines to be “encoded” in this form
''.join(unichr(ord(x)) for x in '\xce\xb1')
although I feel that your lines really fell into this state by different components of your system, I do not agree with the encoding used.
You will probably have to fix the source of the bad “encoding”, and not just fix the data in your database. And the above code may be good at converting your bad data once, but I would advise you not to embed this code in your Django application.
source share