Improve networking exceptions
This commit is contained in:
parent
b698d2e0e1
commit
0f84836533
1 changed files with 22 additions and 20 deletions
|
@ -196,7 +196,7 @@ class ConnectionManager(object):
|
||||||
r = self._requests(action, **request)
|
r = self._requests(action, **request)
|
||||||
log.info("ConnectionManager response status: %s" % r.status_code)
|
log.info("ConnectionManager response status: %s" % r.status_code)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except Exception as e:
|
except requests.RequestException as e:
|
||||||
# Elaborate on exceptions?
|
# Elaborate on exceptions?
|
||||||
log.error(e)
|
log.error(e)
|
||||||
raise
|
raise
|
||||||
|
@ -205,8 +205,8 @@ class ConnectionManager(object):
|
||||||
return etree.fromstring(r.content)
|
return etree.fromstring(r.content)
|
||||||
except etree.ParseError:
|
except etree.ParseError:
|
||||||
# Read response to release connection
|
# Read response to release connection
|
||||||
r.content
|
log.error('Could not parse PMS response: %s' % r.content)
|
||||||
raise
|
raise requests.RequestException
|
||||||
|
|
||||||
def _requests(self, action, **kwargs):
|
def _requests(self, action, **kwargs):
|
||||||
|
|
||||||
|
@ -258,15 +258,18 @@ class ConnectionManager(object):
|
||||||
"""
|
"""
|
||||||
PlexGDM
|
PlexGDM
|
||||||
"""
|
"""
|
||||||
|
servers = []
|
||||||
# setup socket for discovery -> multicast message
|
# setup socket for discovery -> multicast message
|
||||||
|
try:
|
||||||
GDM = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
GDM = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
GDM.settimeout(2.0)
|
GDM.settimeout(2.0)
|
||||||
|
|
||||||
# Set the time-to-live for messages to 2 for local network
|
# Set the time-to-live for messages to 2 for local network
|
||||||
ttl = pack('b', 2)
|
ttl = pack('b', 2)
|
||||||
GDM.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)
|
GDM.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)
|
||||||
|
except (socket.error, socket.herror, socket.gaierror):
|
||||||
servers = []
|
log.error('Socket error, abort PlexGDM')
|
||||||
|
return servers
|
||||||
try:
|
try:
|
||||||
# Send data to the multicast group
|
# Send data to the multicast group
|
||||||
GDM.sendto(MSG_PLEXGDM, (IP_PLEXGDM, PORT_PLEXGDM))
|
GDM.sendto(MSG_PLEXGDM, (IP_PLEXGDM, PORT_PLEXGDM))
|
||||||
|
@ -279,7 +282,7 @@ class ConnectionManager(object):
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
# Probably error: (101, 'Network is unreachable')
|
# Probably error: (101, 'Network is unreachable')
|
||||||
log.error('Could not find Plex servers using GDM')
|
log.error('Could not find Plex servers using PlexGDM')
|
||||||
import traceback
|
import traceback
|
||||||
log.error("Traceback:\n%s" % traceback.format_exc())
|
log.error("Traceback:\n%s" % traceback.format_exc())
|
||||||
finally:
|
finally:
|
||||||
|
@ -349,15 +352,14 @@ class ConnectionManager(object):
|
||||||
Retrieves Plex Media Servers from plex.tv/pms/resources
|
Retrieves Plex Media Servers from plex.tv/pms/resources
|
||||||
"""
|
"""
|
||||||
servers = []
|
servers = []
|
||||||
|
try:
|
||||||
xml = self.requestUrl({
|
xml = self.requestUrl({
|
||||||
'url': 'https://plex.tv/api/resources?includeHttps=1',
|
'url': 'https://plex.tv/api/resources?includeHttps=1',
|
||||||
'type': 'GET',
|
'type': 'GET',
|
||||||
'headers': {'X-Plex-Token': self.plexToken},
|
'headers': {'X-Plex-Token': self.plexToken},
|
||||||
'timeout': 5.0,
|
'timeout': 5.0,
|
||||||
'verify': True})
|
'verify': True})
|
||||||
try:
|
except requests.RequestException:
|
||||||
xml.attrib
|
|
||||||
except AttributeError:
|
|
||||||
log.error('Could not get list of PMS from plex.tv')
|
log.error('Could not get list of PMS from plex.tv')
|
||||||
return servers
|
return servers
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue