Handle "Not enough data to satisfy content length header" errors from broken cameras & NVRs #130
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
response.read()
to catch "Not enough data to satisfy content length header" errorshandle_snapshot_errors
decoratorProblem
Certain Dahua and Lorex camera models return invalid Content-Length headers that are larger or smaller than the actual response body. This causes
response.read()
to either:aiohttp.ClientPayloadError: Not enough data to satisfy content length header
Previously, these errors during the content read phase were not being caught, causing snapshot retrieval to fail with unhandled exceptions which could cause Home Assistant to not be able to setup these devices.
Solution
This PR fixes the issue by:
_try_read_snapshot_content
method that wrapsresponse.read()
with proper error handlinghandle_snapshot_errors
decorator that catches:TimeoutError
→ converts toONVIFTimeoutError
aiohttp.ClientError
(includingClientPayloadError
) → converts toONVIFError
_try_snapshot_uri
(for connection errors)_try_read_snapshot_content
(for read/payload errors)Now when these broken cameras cause payload errors or timeouts during content reading, they're properly caught and converted to appropriate ONVIF exceptions.
Related Issues
Fixes home-assistant/core#148093