Skip to content

Commit 4d72219

Browse files
authored
Improve handling of bad utf-8 (#44)
1 parent 153c567 commit 4d72219

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

onvif/managers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,16 @@ def process(self, content: bytes) -> Any | None:
264264
ASYNC_TRANSPORT,
265265
settings=DEFAULT_SETTINGS,
266266
)
267-
except XMLSyntaxError as exc:
268-
logger.error("Received invalid XML: %s", exc)
269-
return None
267+
except XMLSyntaxError:
268+
try:
269+
envelope = parse_xml(
270+
content.decode("utf-8", "replace").encode("utf-8"),
271+
ASYNC_TRANSPORT,
272+
settings=DEFAULT_SETTINGS,
273+
)
274+
except XMLSyntaxError as exc:
275+
logger.error("Received invalid XML: %s (%s)", exc, content)
276+
return None
270277
return self._operation.process_reply(envelope)
271278

272279

0 commit comments

Comments
 (0)