openHAB 3.2.0 Build #2454
pi4 4GB
Just thought I’d post this in case someone else has this issue …
I doubt I have the terminology right but here goes … I am receiving strings through the REST interface and occasionally the strings have utf8 encoded characters (ie non-ascii) which generates the error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 23: ordinal not in range(128)
after some digging, I found that if I added the following to the beginning of the .py file :
from __future__ import unicode_literals
import sys
reload(sys)
sys.setdefaultencoding('utf8')
it solves the problem … perhaps there is a better way to solve this? Isn’t there a way to change the system setting as a default? Maybe there are reasons not to do this?