From: Simon McVittie Date: Fri, 24 Apr 2020 11:25:41 +0100 Subject: avahi-discover: Don't decode unicode strings, only bytestrings Unicode strings (unicode in Python 2, str or unicode in Python 3) don't have a decode method; only bytestrings (str or bytes in Python 2, bytes in Python 3) have that. Decode exactly the strings that need decoding. Resolves: https://github.com/lathiat/avahi/issues/275 Signed-off-by: Simon McVittie Forwarded: https://github.com/lathiat/avahi/pull/282 --- avahi-python/avahi-discover/avahi-discover.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/avahi-python/avahi-discover/avahi-discover.py b/avahi-python/avahi-discover/avahi-discover.py index 4a2b575..fddf4a5 100755 --- a/avahi-python/avahi-discover/avahi-discover.py +++ b/avahi-python/avahi-discover/avahi-discover.py @@ -238,15 +238,17 @@ class Main_window: txts+="" + _("TXT") + " %s = %s\n" % (k,v) else: txts = "" + _("TXT Data:") + " " + _("empty") + "" - - txts = txts.decode("utf-8") + + if isinstance(txts, bytes): # Python 2 + txts = txts.decode("utf-8") infos = "" + _("Service Type:") + " %s\n" infos += "" + _("Service Name:") + " %s\n" infos += "" + _("Domain Name:") + " %s\n" infos += "" + _("Interface:") + " %s %s\n" infos += "" + _("Address:") + " %s/%s:%i\n%s" - infos = infos.decode("utf-8") + if isinstance(infos, bytes): # Python 2 + infos = infos.decode("utf-8") infos = infos % (stype, name, domain, self.siocgifname(interface), self.protoname(protocol), host, address, port, txts.strip()) self.info_label.set_markup(infos)