Markus Hedlund
Markus Hedlund

Reputation: 24334

Print and UnicodeEncodeError

I know there are lots of similar questions, but none seem to answer my question.

Getting this error:

print('Dimming', device.name, 'to', level)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe5' in position 3: ordinal not in range(128)

If I test to print that character, it works:

$ python3
Python 3.4.3 (default, Oct 14 2015, 20:33:09)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('\xe5')
å
>>> print('å')
å

If I add .encode('utf-8') it just outputs Dimming b'Byr\xc3\xa5' to 100

This is a process running on Ubuntu via Upstart. How can I make it output the correct character?

Upvotes: 1

Views: 99

Answers (1)

Markus Hedlund
Markus Hedlund

Reputation: 24334

Add env LANG=en_US.UTF-8 to the Upstart script conf file.

Upvotes: 2

Related Questions