Try 3x before declaring plex connection dead
This commit is contained in:
parent
43b0af936f
commit
fb46c41294
1 changed files with 28 additions and 18 deletions
|
@ -332,6 +332,7 @@ class PlexAPI():
|
||||||
"""
|
"""
|
||||||
Checks connection to a Plex server, available at url. Can also be used
|
Checks connection to a Plex server, available at url. Can also be used
|
||||||
to check for connection with plex.tv.
|
to check for connection with plex.tv.
|
||||||
|
Will check up to 3x until reply with False
|
||||||
|
|
||||||
Input:
|
Input:
|
||||||
url URL to Plex server (e.g. https://192.168.1.1:32400)
|
url URL to Plex server (e.g. https://192.168.1.1:32400)
|
||||||
|
@ -359,6 +360,10 @@ class PlexAPI():
|
||||||
url = 'https://plex.tv/api/home/users'
|
url = 'https://plex.tv/api/home/users'
|
||||||
else:
|
else:
|
||||||
url = url + '/library/onDeck'
|
url = url + '/library/onDeck'
|
||||||
|
# Check up to 3 times before giving up - this sometimes happens when
|
||||||
|
# PKC was just started
|
||||||
|
count = 0
|
||||||
|
while count < 3:
|
||||||
try:
|
try:
|
||||||
answer = requests.get(url,
|
answer = requests.get(url,
|
||||||
headers={},
|
headers={},
|
||||||
|
@ -368,15 +373,20 @@ class PlexAPI():
|
||||||
except requests.exceptions.ConnectionError as e:
|
except requests.exceptions.ConnectionError as e:
|
||||||
self.logMsg("Server is offline or cannot be reached. Url: %s "
|
self.logMsg("Server is offline or cannot be reached. Url: %s "
|
||||||
"Header: %s Error message: %s"
|
"Header: %s Error message: %s"
|
||||||
% (url, header, e), -1)
|
% (url, header, e), 0)
|
||||||
return False
|
count += 1
|
||||||
|
continue
|
||||||
except requests.exceptions.ReadTimeout:
|
except requests.exceptions.ReadTimeout:
|
||||||
self.logMsg("Server timeout reached for Url %s with header %s"
|
self.logMsg("Server timeout reached for Url %s with header %s"
|
||||||
% (url, header), -1)
|
% (url, header), 0)
|
||||||
return False
|
count += 1
|
||||||
|
continue
|
||||||
|
else:
|
||||||
result = answer.status_code
|
result = answer.status_code
|
||||||
self.logMsg("Result was: %s" % result, 1)
|
self.logMsg("Result was: %s" % result, 1)
|
||||||
return result
|
return result
|
||||||
|
self.logMsg('Failed to connect to %s too many times.' % url, -1)
|
||||||
|
return False
|
||||||
|
|
||||||
def GetgPMSKeylist(self):
|
def GetgPMSKeylist(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue