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,24 +360,33 @@ 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'
|
||||||
try:
|
# Check up to 3 times before giving up - this sometimes happens when
|
||||||
answer = requests.get(url,
|
# PKC was just started
|
||||||
headers={},
|
count = 0
|
||||||
params=header,
|
while count < 3:
|
||||||
verify=sslverify,
|
try:
|
||||||
timeout=timeout)
|
answer = requests.get(url,
|
||||||
except requests.exceptions.ConnectionError as e:
|
headers={},
|
||||||
self.logMsg("Server is offline or cannot be reached. Url: %s "
|
params=header,
|
||||||
"Header: %s Error message: %s"
|
verify=sslverify,
|
||||||
% (url, header, e), -1)
|
timeout=timeout)
|
||||||
return False
|
except requests.exceptions.ConnectionError as e:
|
||||||
except requests.exceptions.ReadTimeout:
|
self.logMsg("Server is offline or cannot be reached. Url: %s "
|
||||||
self.logMsg("Server timeout reached for Url %s with header %s"
|
"Header: %s Error message: %s"
|
||||||
% (url, header), -1)
|
% (url, header, e), 0)
|
||||||
return False
|
count += 1
|
||||||
result = answer.status_code
|
continue
|
||||||
self.logMsg("Result was: %s" % result, 1)
|
except requests.exceptions.ReadTimeout:
|
||||||
return result
|
self.logMsg("Server timeout reached for Url %s with header %s"
|
||||||
|
% (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):
|
def GetgPMSKeylist(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue