ASCII编解码器无法编码字符 [英] ascii codec can't encode character

查看:180
本文介绍了ASCII编解码器无法编码字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to create a string with special characters from portuguese-brazil (e.g. á, à, â, ç)

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)

我需要将其发送给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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆