I'm trying to create a string with special characters from portuguese-brazil (eg á, à, â, ç)
push_message = 'á'
push_message.decode().encode('utf-8')
But I'm getting this error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 0: ordinal not in range(128)
I need to send this to Parse Api, and Parse Api just allows utf8 encoding. What can I do to solve this?
EDIT
When I try
push_message.decode('utf-8')
I get
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 0: ordinal not in range(128)
When I try
push_message.decode('latin-1')
I get
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 0: ordinal not in range(128)
它像这样工作:
unicode(push_message.decode('utf-8'))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.