Skip to content

Commit 809e444

Browse files
authored
Handle cameras that respond to GetSnapshotUri with no Uri (#49)
1 parent db90703 commit 809e444

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

onvif/client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
logging.basicConfig(level=logging.INFO)
3434
logging.getLogger("zeep.client").setLevel(logging.CRITICAL)
3535

36-
36+
_SENTINEL = object()
3737
_WSDL_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "wsdl")
3838
_DEFAULT_TIMEOUT = 90
3939
_PULLPOINT_TIMEOUT = 90
@@ -501,13 +501,19 @@ async def close(self) -> None:
501501

502502
async def get_snapshot_uri(self, profile_token: str) -> str:
503503
"""Get the snapshot uri for a given profile."""
504-
uri = self._snapshot_uris.get(profile_token)
505-
if uri is None:
504+
uri = self._snapshot_uris.get(profile_token, _SENTINEL)
505+
if uri is _SENTINEL:
506506
media_service = await self.create_media_service()
507507
req = media_service.create_type("GetSnapshotUri")
508508
req.ProfileToken = profile_token
509509
result = await media_service.GetSnapshotUri(req)
510-
uri = normalize_url(result.Uri)
510+
try:
511+
uri = normalize_url(result.Uri)
512+
except KeyError:
513+
logger.warning(
514+
"%s: The device returned an invalid snapshot URI", self.host
515+
)
516+
uri = None
511517
self._snapshot_uris[profile_token] = uri
512518
return uri
513519

0 commit comments

Comments
 (0)