From d58b5ad77718fd32e386d6ce06c8ffb9095729bf Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 14 Mar 2018 19:40:39 +0545 Subject: [PATCH] core: prevent creation of unicode Message.data Was triggering a crash indirectly due to Ansible passing us Unicode strings. Needs a better fix. --- mitogen/core.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mitogen/core.py b/mitogen/core.py index 39530454..3060e1b6 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -620,6 +620,9 @@ class LogHandler(logging.Handler): try: msg = self.format(rec) encoded = '%s\x00%s\x00%s' % (rec.name, rec.levelno, msg) + if isinstance(encoded, unicode): + # Logging package emits both :( + encoded = encoded.encode('utf-8') self.context.send(Message(data=encoded, handle=FORWARD_LOG)) finally: self.local.in_emit = False