Search code examples
pythonserverasciiubuntu-20.04python-unicode

"`ascii‘ codec can’t enforce character u’\u2022‘ in position 206: ordinal not in range (128)"


I get this error when I try to execute my Python script on my Ubuntu 20.4 home server:

`ascii‘ codec can’t enforce character u’\u2022‘ in position 206: ordinal not in range (128)


Solution

  • You should read the Python Unicode HOWTO. This error is the first 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()