Fix uncaught ConnectionError in scpd_post and scpd_get #22

Merged
jackrobison merged 3 commits from catch-connection-error into master 2020-01-15 22:37:03 +01:00
Showing only changes of commit 6d52d76af6 - Show all commits

View file

@ -7,7 +7,7 @@ from aioupnp.util import flatten_keys
CONTENT_PATTERN = re.compile(
"(\<\?xml version=\"1\.0\"\?\>(\s*.)*|\>)".encode()
"(\<\?xml version=\"1\.0\"\?\>(\s*.)*|\>)"
)
XML_ROOT_SANITY_PATTERN = re.compile(
@ -39,8 +39,8 @@ def serialize_scpd_get(path: str, address: str) -> bytes:
def deserialize_scpd_get_response(content: bytes) -> Dict[str, Any]:
if XML_VERSION.encode() in content:
parsed: List[Tuple[bytes, bytes]] = CONTENT_PATTERN.findall(content)
xml_dict = xml_to_dict((b'' if not parsed else parsed[0][0]).decode())
parsed: List[Tuple[bytes, bytes]] = CONTENT_PATTERN.findall(content.decode())
xml_dict = xml_to_dict('' if not parsed else parsed[0][0])
return parse_device_dict(xml_dict)
return {}