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
|
||||
to check for connection with plex.tv.
|
||||
Will check up to 3x until reply with False
|
||||
|
||||
Input:
|
||||
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'
|
||||
else:
|
||||
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:
|
||||
answer = requests.get(url,
|
||||
headers={},
|
||||
|
@ -368,15 +373,20 @@ class PlexAPI():
|
|||
except requests.exceptions.ConnectionError as e:
|
||||
self.logMsg("Server is offline or cannot be reached. Url: %s "
|
||||
"Header: %s Error message: %s"
|
||||
% (url, header, e), -1)
|
||||
return False
|
||||
% (url, header, e), 0)
|
||||
count += 1
|
||||
continue
|
||||
except requests.exceptions.ReadTimeout:
|
||||
self.logMsg("Server timeout reached for Url %s with header %s"
|
||||
% (url, header), -1)
|
||||
return False
|
||||
% (url, header), 0)
|
||||
count += 1
|
||||
continue
|
||||
else:
|
||||
result = answer.status_code
|
||||
self.logMsg("Result was: %s" % result, 1)
|
||||
return result
|
||||
self.logMsg('Failed to connect to %s too many times.' % url, -1)
|
||||
return False
|
||||
|
||||
def GetgPMSKeylist(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue