首页 > 解决方案 > UnicodeEncodeError:“ascii”编解码器无法对位置 25-32 中的字符进行编码:序数不在范围内(128)

问题描述

>>a=u' Test for Garbling issue \ufffd\u3000\u2605\ufffd\u3000\u30c6\u30b9\u30c8 1'

>>a.encode('us-ascii')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 25-32: ordinal not in range(128)


>> print a.encode('utf-8')
Test for Garbling issue � ★� テスト 1

但预期的输出是:

Test for Garbling issue ① ★㈱ テスト 1

标签: pythonpython-2.7unicodepython-unicodeunicode-string

解决方案


推荐阅读