Unicode in Python

always a pain

10 Sep 2022 starting note.

Toubleshooting

Solve Error: 'ascii' codec can't encode character '\xa0' in position xx

10 Sep 2022 trying:
Add PYTHONIOENCODING="UTF-8" to PATH, ie add to .env if runnning dotenv How to save confidential data in environment variables with dotenv.
-> Not working

Tests:

  1. 'Automatyczna odpowiedź'

prints: Automatyczna odpowiedź
output script: ERROR with Automatyczna odpowiedź: 'ascii' codec can't encode character '\u017a' in position 31: ordinal not in range(128)

  1. 'Automatyczna odpowiedź'.encode("utf-8")

prints: b'Automatyczna odpowied\xc5\xba' 🤔
output script: ERROR with b'Automatyczna odpowied\xc5\xba': "subject" expected str value, "<class 'int'>" received

  1. 'Automatyczna odpowiedź'.encode("ascii")

output script: UnicodeEncodeError: 'ascii' codec can't encode character '\u017a' in position 21: ordinal not in range(128)

Still not working :/

Resources

To watch:

To read:

going deeper:

links

social