簡體   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