I am trying to convert unicode to string, but I am getting UnicodeDecodeError. The original issue is related to working with a json return and creating a string, but here is a simplified example:
raw = unicode("Soporté")
print stringUnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 6: ordinal not in range(128)
I have tried the suggestion from here: Rename layer with unsupported signs in a mxd via python?
raw = unicode("Soporté")
string = raw.decode('utf-8')
print string
And here: Write Russian field names to txt
raw = unicode("Soporté")
string = raw.encode('utf-8')
print stringBut I get the same error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 6: ordinal not in range(128)
Solved! Go to Solution.
raw = u'Soporté'
>>> print raw
Soporté
Thanks Bruce Harold! That works for printing the text, but I've added some complexity beyond printing. I am trying to concatenate the unicode with a string and append it to a list.
list = []
raw = u'Soporté'
list.append("Department: {}".format(raw))
print list
Add the 'u' in front of my concatenated string as Bruce Harold suggested worked. Thanks!
list = []
raw = u'Soporté'
list.append(u"Department: {}".format(raw))
print list