Closed RaveGun closed 3 years ago
generic documentation generic source (message by IssueLinks)
Actually I just realize this shall be more of a: "integration: camera" label.
If you are using a username/password, please try including them separately in the yaml instead of embedding them in still_image_url.
Has anything changed in respect to generic camera implementation?
The proposed solution will not work because is not a normal login. This is how the secret URL looks like:
camera_front_img: http://192.168.1.70/cgi-bin/api.cgi?cmd=Snap&channel=0&user=1ooser&password=muchs3cur3w0w
The link above works just fine on the browser.
There must be something with the tockens on the Core side.
I see. That url should be fine.
Yes, there were changes in both the generic camera integration as well as in the base camera integration itself. The generic camera integration was changed to use the httpx library, but any failures there should leave log messages. The changes to the base camera integration were mostly to do with stream, so I wouldn't expect that those would affect the still images.
Also interesting is the fact that it works for a while after a reboot.
To rule out the generic component, can you try reverting the generic/camera.py
to the previous working version?
I have changed the generic/camera.py in the Core container with this version:
https://github.com/home-assistant/core/blob/0e98bc5ea23cd15ecdc17a8318250b4a8fbe9478/homeassistant/components/generic/camera.py
For the moment is works after the restart. I will report back when / if it stops working again.
With the changed camera.py, as above described, it is still working fine. No issues until now.
That's interesting, thanks for the update. For the version with problems, how long does it take for the images to not work?
Last time it was after about an hour or so, but I did not tracked this actively.
Hi,
Thanks for the update. I saw what you did there. This might have been the issue. I just made the changes, restarted the Core and so far it is running well. Will report back in a couple of hours.
Thanks again.
I spoke too soon. These errors showed up in the log:
Logger: aiohttp.server
Source: components/generic/camera.py:152
First occurred: 7:31:48 PM (3 occurrences)
Last logged: 7:32:11 PM
Error handling request
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/generic/camera.py", line 140, in async_camera_image
response = await async_client.get(
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1548, in get
return await self.request(
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1371, in request
response = await self.send(
File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1416, in send
await response.aread()
File "/usr/local/lib/python3.8/site-packages/httpx/_models.py", line 1234, in aread
self._content = b"".join([part async for part in self.aiter_bytes()])
File "/usr/local/lib/python3.8/site-packages/httpx/_models.py", line 1234, in <listcomp>
self._content = b"".join([part async for part in self.aiter_bytes()])
File "/usr/local/lib/python3.8/site-packages/httpx/_models.py", line 1247, in aiter_bytes
async for chunk in self.aiter_raw():
File "/usr/local/lib/python3.8/site-packages/httpx/_models.py", line 1286, in aiter_raw
async for part in self.stream:
File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 61, in __aiter__
async for chunk in self.stream:
File "/usr/local/lib/python3.8/site-packages/httpcore/_bytestreams.py", line 73, in __aiter__
async for chunk in self._aiterator:
File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http11.py", line 155, in _receive_response_data
event = await self._receive_event(timeout)
File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http11.py", line 172, in _receive_event
data = await self.socket.read(self.READ_NUM_BYTES, timeout)
File "/usr/local/lib/python3.8/site-packages/httpcore/_backends/asyncio.py", line 144, in read
return await asyncio.wait_for(
File "/usr/local/lib/python3.8/asyncio/tasks.py", line 481, in wait_for
await waiter
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
resp = await self._request_handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 56, in security_filter_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 129, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 496, in get
return await self.handle(request, camera)
File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 513, in handle
image = await camera.async_camera_image()
File "/usr/src/homeassistant/homeassistant/components/generic/camera.py", line 152, in async_camera_image
response.close()
UnboundLocalError: local variable 'response' referenced before assignment
I see, I updated the file to fix that. Can you try again?
It is now up and running. There are no log entries either. I just want to mention that the previous fix showed the same issue.
Unfortunately it stopped working after a while. The last update did not fixed the issue.
I have a doorbell automation that is sending a snapshot to my phone from the same URL as in the camera configuration and it is working fine. This means that getting the snapshot works even if the generic:camera stopped. But these are anyhow not related.
Is there anything else I should try? Is there something else on my side that is misbehaving? Is only my installation affected? Hmm..
How long did it work before not working? Any logs? I made another update to the file, see if that helps anything.
Thanks for the info. The update is up and running.
Last time it was again around one hour. I cannot tell exactly as it was in the middle of the night. There were also no logs, or nothing special nor related to the issue. All of my cameras are scheduled to restart once a week overnight on a different day and time. So there are the usual cannot get image from "insert_camera_name".
I will let you know how it went overnight.
Hi,
It sopped after 2,5 Hours and now there are old previews.
No information in the logs but I do have the default log level set to error. So the asyncio.CancelledError
will not be logged.
I have added now these two lines to the logger:
homeassistant.components.camera: debug
homeassistant.components.generic.camera: debug
Maybe this will show more.
After the restart it stopped after 1 hour and 15 minutes but now in the log are 1900+ cancelling getting camera image warnings for all generic cameras.
Did it always show old previews? It seems like at some point the client stops working and subsequent timeouts get triggered at the higher level (in camera as opposed to generic). I changed the file to log out all unknown exceptions to error - let's see if we can pick up anything.
No, it did not always shown old previews. Only the latest updates with the return self._last_image are doing this.
There were about 12k cancel warnings but no unknown error so far. I disabled now the logging for the warnings and restarted the Core.
Is the CancelledError
exception triggered by the 500 Internal Server Error
?
The CancelledError
exception comes when the camera
component times out when getting an image from generic
. It's not strange to get that once or twice if there is some connectivity issue, but the problem is that whatever is causing the timeout keeps on happening.
There seem to be a number of outstanding issues with the httpx
async client. I changed the file to use the sync client instead. Can you see if that fixes things?
LOL, now I am getting 500: Internal Server Error
also from raw.githubusercontent.com trying to download the updated camera.py
.
After GitHub went back online I did the update and is working normally for the last 12 hours. The sync access did the trick.
Thank you.
@RaveGun It was suggested we try to work around the issue while still using the async api. I've updated the camera.py file. Can you try it again?
Update done and restarted. The cameras are working after the restart. I will be back with more information in a couple of hours. Thanks.
Hello,
Until now everything looks good. I guess that the issue has been fixed with the latest update.
Thank you for your time and support.
Hello,
Logger: homeassistant.components.generic.camera Source: components/generic/camera.py:149 Error getting new camera image from imou_cue2c: Unsupported URL protocol 'rtsp'
I am on HA 2021.3.4.
Any ideas, what can I check?
Thanks, Joc.
Same issue here. Strange that the camera image comes up fine on the iphone Home Assistant app. I see that there is an updated file "camera.py". unfortunately, I have no idea what to do with the file or where it needs to go. Searched HA file system and found no file wit the same name. Is there any docs that detail what needs to be done in order to update the file?
Thank you, Andy
@HAnoobhacker
Is the image on the app also actual?
Depending on your installation the file is located here:
/core/homeassistant/components/generic/
In have a docker installation so I had to connect to the container's console and change the file from in the image from within.
@Joc007 sorry, I cannot help with this. Maybe @uvjustin knows how is the rtsp protocol handled.
Yes. The image is "Live Broadcast". I'm running core-2021.3.4 Home Assistant OS 5.12. in VirtualBox 6.1 on Ubuntu Desktop 20.4. I'm not seeing that directory structure in the HA VM.
@Joc007 It looks like your setup is incorrect. RTSP urls are camera feeds which are used in stream_source
, while the still_image_url
should be a http or https image url.
I've been having this same problem and for me it coexists with my REST sensors failing. I've been moving my REST calls over to NodeRed and while this has solved the issues with REST, I am still having the issue with generic cams. It's frustrating because I've had a stable HA for years and these cams have worked forever until a month or two ago (maybe three).
Here's the info I posted in issue #43600 :
Been moving my REST calls to Node Red as per @tiagofreire-pt and while it's helped with my REST issues, I am also having issues with generic based URL cameras, such as ones for radar/weather conditions as well as those that make a REST call to get a snapshot (e.g. getting a snap from a tablet cam via Fully Kiosk). When the existing HA REST sensors start to fail on me, so do these types of cameras. It's making me wonder if the issue isn't REST but the http/https calls. It doesn't matter whether these calls are internal or external to my network. Even after these fail, I can still ping or do an nslookup from the HA console so I know there isn't a network/DNS issue involved. I've tried debugging aiohttp but see nothing there. It's really getting frustrating. I even built a new VM in Virtualbox and restored my snapshot to it thinking there might be some corruption in the core but it's still there.
version | core-2021.3.4 |
---|---|
installation_type | Home Assistant OS |
dev | false |
hassio | true |
docker | true |
virtualenv | false |
python_version | 3.8.7 |
os_name | Linux |
os_version | 5.4.99 |
arch | x86_64 |
timezone | America/New_York |
@rpitera The issue with generic was introduced in https://github.com/home-assistant/core/pull/46576 when we switched the http library to use httpx
. Unfortunately it looks like there is an outstanding issue with httpx
not freeing up resources when the request times out and gets cancelled.
We have a PR to work around this here: https://github.com/home-assistant/core/pull/47852 . There is some info at the top of the PR with links to the httpx
issues.
It's possible that the rest
component has a similar issue with the library.
@uvjustin Thanks so much for the reply; running out of places to look for resources so I'll read the issues/PRs you referenced. Appreciate the pointer. I've been setting up NR to now capture my images and save them to a local file and displaying them using the local file camera. But I'd really like to get to the bottom of it since I still have a few cams that won't work with my work-around.
The problem
Since the update to core-2021.3.x the generic IP cameras are no longer displayed in Lovelace. There is no issue or anything else in the log.
What is version of Home Assistant Core has the issue?
core-2021.3.2
What was the last working version of Home Assistant Core?
core-2021.2.x
What type of installation are you running?
Home Assistant Supervised
Integration causing the issue
integration: camera
Link to integration documentation on our website
https://www.home-assistant.io/integrations/generic/
Example YAML snippet
Anything in the logs that might be useful for us?
Upon inspecting the page I saw that there are errors reported in the browser console.
After a Core restart it works for a while. The same behavior is on any web browser and also on the companion app.