Reputation: 13562
I tried to decode a hex string but special characters.
When I run
codecs.decode("5469eb73746f2026204b53484d5220666561742e205661737379", "hex")
I get b'Ti\xebsto & KSHMR feat. Vassy'
but I want Tiësto & KSHMR feat. Vassy
I checked the Hex code online but it is correct. Do I need another function or do I just miss one step?
Upvotes: 0
Views: 207
Reputation: 1122382
You decoded the hex value to a bytes
object. If you expected (Unicode) text, decode the bytes with a valid encoding; you appear to have either Latin 1 or Windows Codepage 1252 data here:
>>> import codecs
>>> codecs.decode("5469eb73746f2026204b53484d5220666561742e205661737379", "hex")
b'Ti\xebsto & KSHMR feat. Vassy'
>>> _.decode('latin1')
'Tiësto & KSHMR feat. Vassy'
Upvotes: 4