简体   繁体   中英

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

The version of my python is 2.7.

For some reason, I need to use rot13 to convert a paragraph with encoding 'utf-8'. But when I run commands as followed:

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

I get the following error message:

UnicodeEncodeError: 'charmap' codec can't encode character u'\€' in position 0: character maps to <undefined> . How can I fix this error? I was trapped in this error for long time, and can't fix it by the method on Google.

The rot13 codec can't do this in Python 2. It's hardcoded to use charmap. Switch to Python 3 or just write your own rot13.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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