简体   繁体   中英

`ascii‘ codec can’t enforce character u’\u2022‘ in position 206:

I get this error when I try to execute my python script on my Ubuntu 20.4 homeserver:

`ascii' codec can't enforce character u'\•' in position 206: ordinal not in range (128)

You should read the Python Unicode HOWTO . This error is thefirst example .

Basically, you shouldn't str to convert from Unicode to encoded text/bytes.

Instead, use .encode() to encode the string:

text = 'some_str'.encode('utf-8').strip()

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