[英]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.