Here ist my code:
util.py:
from core.log import logging, LOG_PREFIX
from core.jsr223.scope import actions
from configuration import admin_email, telegram_bot
def send_info_telegram(message):
out = str(message)
logging.getLogger("{}.Jython_TEST".format(LOG_PREFIX)).info(out.format(5 + 5))
telegramAction = actions.get("telegram", telegram_bot)
telegramAction.sendTelegram(out)
test.py:
from core.log import logging, LOG_PREFIX #, log_traceback
from configuration import admin_email, telegram_bot
import personal.util
reload(personal.util)
from personal.util import send_info_telegram
AlarmWert = 50
AlarmwertQuantityType = str(AlarmWert) + u" °C"
Meldungstext = "Sensors > " + AlarmwertQuantityType
send_info_telegram(Meldungstext) # line 28
result in openhab.log:
2020-03-05 13:16:32.245 [ERROR] [ion.module.script.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/personal/test.py': UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 23: ordinal not in range(128) in <script> at line number 28
how do I change util.py so that I can pass unicode characters?
the following code does not cause any problems:
LOG = logging.getLogger("{}.Jython_TEST".format(LOG_PREFIX))
LOG.info(AlarmwertQuantityType)
2020-03-05 13:26:28.236 [INFO ] [jsr223.jython.Jython_TEST ] - 50 °C