From d103297d06550ef0cefd8737f3f87be072165586 Mon Sep 17 00:00:00 2001 From: Kashiko Koibumi Date: Sat, 1 Jun 2024 13:08:38 +0900 Subject: [PATCH] fix UPnP to work with Python3 --- src/upnp.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/upnp.py b/src/upnp.py index e3cb04bd..72d17343 100644 --- a/src/upnp.py +++ b/src/upnp.py @@ -94,12 +94,12 @@ class Router: # pylint: disable=old-style-class self.address = address - row = ssdpResponse.split('\r\n') + row = ssdpResponse.split(b'\r\n') header = {} for i in range(1, len(row)): - part = row[i].split(': ') + part = row[i].split(b': ') if len(part) == 2: - header[part[0].lower()] = part[1] + header[part[0].decode("utf-8", "replace").lower()] = part[1].decode("utf-8", "replace") try: self.routerPath = urlparse(header['location']) @@ -222,10 +222,6 @@ class uPnPThread(StoppableThread): def run(self): """Start the thread to manage UPnP activity""" - if six.PY3: - logger.warning("UPnP is disabled currently, due to incompleted migration to Python3.") - return - logger.debug("Starting UPnP thread") logger.debug("Local IP: %s", self.localIP) lastSent = 0 @@ -320,7 +316,7 @@ class uPnPThread(StoppableThread): try: logger.debug("Sending UPnP query") - self.sock.sendto(ssdpRequest, (uPnPThread.SSDP_ADDR, uPnPThread.SSDP_PORT)) + self.sock.sendto(ssdpRequest.encode("utf8", "replace"), (uPnPThread.SSDP_ADDR, uPnPThread.SSDP_PORT)) except: # noqa:E722 logger.exception("UPnP send query failed")