From 531dba40bf922d4a0db9d44ff6194f1e64940e8c Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Wed, 10 Feb 2016 13:02:58 +0100 Subject: [PATCH] Fix to Plex Companion response not conform to HTTP standards content length is wrong, causing thread to lock for several seconds --- resources/lib/downloadutils.py | 7 ++++--- resources/lib/plexbmchelper/subscribers.py | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 518672dc..bd3f6333 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -185,11 +185,12 @@ class DownloadUtils(): header = plx.getXArgsDeviceInfo(options=options) return header - def downloadUrl(self, url, postBody=None, type="GET", parameters=None, authenticate=True, headerOptions={}): + def downloadUrl(self, url, postBody=None, type="GET", parameters=None, authenticate=True, headerOptions={}, timeout=None): # self.logMsg("=== ENTER downloadUrl ===", 2) - timeout = self.timeout + if timeout is None: + timeout = self.timeout default_link = "" try: @@ -365,7 +366,7 @@ class DownloadUtils(): except requests.exceptions.ConnectTimeout as e: self.logMsg("Server timeout at: %s" % url, 0) - self.logMsg(e, 1) + # self.logMsg(e, 1) except requests.exceptions.HTTPError as e: diff --git a/resources/lib/plexbmchelper/subscribers.py b/resources/lib/plexbmchelper/subscribers.py index 12ca0d33..89799ca9 100644 --- a/resources/lib/plexbmchelper/subscribers.py +++ b/resources/lib/plexbmchelper/subscribers.py @@ -243,10 +243,14 @@ class Subscriber: url = self.protocol + '://' + self.host + ':' + self.port \ + "/:/timeline" + # Choose an extremely low timeout due to Plex players response not + # being conform to HTTP standards (content length is wrong). Otherwise, + # This thread gets blocked for a couple of seconds response = self.download.downloadUrl( url, postBody=msg, - type="POSTXML") + type="POSTXML", + timeout=0.001) # if not requests.post(self.host, self.port, "/:/timeline", msg, getPlexHeaders(), self.protocol): # subMgr.removeSubscriber(self.uuid) if response in [False, None, 401]: