繁体   English   中英

ASCII编解码器无法编码字符

[英]ascii codec can't encode character

我正在尝试使用葡萄牙语-巴西(例如á,à,â,ç)中的特殊字符创建一个字符串

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编码。 我该怎么解决?

编辑

当我尝试

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')) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM