3 from __future__
import annotations
7 from zeep.exceptions
import Fault
11 """Stringify ONVIF subcodes."""
12 if isinstance(subcodes, list):
13 return [code.text
if hasattr(code,
"text")
else str(code)
for code
in subcodes]
14 return [
str(subcodes)]
18 """Stringify ONVIF error."""
19 if isinstance(error, Fault):
20 message = error.message
21 if error.detail
is not None:
23 if isinstance(error.detail, bytes):
24 detail = error.detail.decode(
"utf-8",
"replace")
26 detail =
str(error.detail)
27 message +=
": " + detail
28 if error.code
is not None:
29 message += f
" (code:{error.code})"
30 if error.subcodes
is not None:
32 f
" (subcodes:{','.join(extract_subcodes_as_strings(error.subcodes))})"
35 message += f
" (actor:{error.actor})"
38 return message
or f
"Device sent empty error with type {type(error)}"
42 """Return True if error is an authentication error.
44 Most of the tested cameras do not return a proper error code when
45 authentication fails, so we need to check the error message as well.
47 if not isinstance(error, Fault):
51 "NotAuthorized" in code
str stringify_onvif_error(Exception error)
bool is_auth_error(Exception error)
list[str] extract_subcodes_as_strings(Any subcodes)