ascii 编解码器无法编码字符 [英] ascii codec can't encode character
本文介绍了ascii 编解码器无法编码字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用来自葡萄牙语-巴西的特殊字符(例如 á、à、â、ç)创建一个字符串
I'm trying to create a string with special characters from portuguese-brazil (e.g. á, à, â, ç)
push_message = 'á'
push_message.decode().encode('utf-8')
但我收到此错误:
UnicodeEncodeError: 'ascii' codec can't encode character u'xe1' in position 0: ordinal not in range(128)
我需要将此发送到 Parse Api,而 Parse Api 只允许 utf8 编码.我该怎么做才能解决这个问题?
I need to send this to Parse Api, and Parse Api just allows utf8 encoding. What can I do to solve this?
编辑
当我尝试
push_message.decode('utf-8')
我明白
UnicodeEncodeError: 'ascii' codec can't encode character u'xe1' in position 0: ordinal not in range(128)
当我尝试
push_message.decode('latin-1')
我明白
UnicodeEncodeError: 'ascii' codec can't encode character u'xe1' in position 0: ordinal not in range(128)
推荐答案
它是这样工作的:
unicode(push_message.decode('utf-8'))
这篇关于ascii 编解码器无法编码字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文