繁体   English   中英

使用unicode.encode('rot13')时如何修复UnicodeEncodingError

[英]How to fix UnicodeEncodingError when using unicode.encode('rot13')

我的python版本是2.7。

由于某些原因,我需要使用rot13来转换编码为'utf-8'的段落。 但是当我如下运行命令时:

s = u'€'
res = unicode.encode('rot13')

我收到以下错误消息:

UnicodeEncodeError:'charmap'编解码器无法在位置0编码字符u'\\ u20ac':字符映射到<undefined> 如何解决此错误? 我被这个错误困扰了很长时间,无法通过Google上的方法解决。

rot13编解码器在Python 2中无法做到这一点。它被硬编码为使用charmap。 切换到Python 3或只编写自己的rot13。

暂无
暂无

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

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