Closed jenche closed 3 years ago
Sometime soon I will need to do some unicode testing and cleanup. I'll take a look at this one tonight. My WAG is that there is a log entry in core.rules causing the issue.
@jenche, it was a log entry as I suspected. I will submit a PR for this, but you can correct this by changing line 129 of core.rules to...
log.debug(u"Added rule [{}]".format(rule.name))
In case you missed it, there's a 'u' added to make a unicode string :slightly_smiling_face:. You'll need to reload the module in your script (or restart OH) for the change to be picked up. Thank you for reporting this!
Great, thanks for fixing it that fast !
Mmmm, I applied the fix in core.rules as you told me, restarted openhab, but still have the same error. Is it possible there's another unicode encoding problem elsewhere in the code ?
Yes, it is very possible! But in testing, I was able to use unicode in a rule name without error using this fix. It's been a while though, so I'll test again. I was hoping to merge this today. What was your error?
It's exactly the same than in my first post :UnicodeEncodeError: 'ascii' codec can't encode character u'\xf4' in position 5: ordinal not in range(128) in <script> at line number 10
Ah, found it.
Need to change line 98 in core/rules.py to callback.log = logging.getLogger(u"{}.{}".format(LOG_PREFIX, name))
My bad... I already have this, so I neglected to point out this change.... sorry about that!
I finally got this merged in #372.
I tried to define a rule with the following decorator:
@rule(u'Contrôle de l\'alarme', description=u'Active ou désactive l\'alarme')
When the script containing this rule loads, I get the following error:
Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/personal/alarme.py': UnicodeEncodeError: 'ascii' codec can't encode character u'\xf4' in position 5: ordinal not in range(128) in <script> at line number 10
Replacing the "ô" character in the rule name by "o" fixes the problem. Surprisingly, having this character in the rule description doesn't cause any problem.
Environment (please complete the following information):