MJPEG IP Camera & aiohttp error

Hello,

I have installed 2 cameras using the “MJPEG IP Camera” integration, like this :

### my integration code looks like :

camera:
  - platform: mjpeg
    name: MyCam
    mjpeg_url: http://<user>:<password>@xxx.xxx.x.x:80/video.mjpeg
    verify_ssl: false
    authentication: basic

And since then I regularly get aiohttp errors :

Logger: aiohttp.server
Source: helpers/aiohttp_client.py:172
First occurred: 09:08:01 (2 occurrences)
Last logged: 09:18:13

Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/forwarded.py", line 220, in forwarded_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/ban.py", line 78, in ban_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/auth.py", line 138, in auth_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/view.py", line 135, in handle
    result = await result
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/camera/__init__.py", line 618, in get
    return await self.handle(request, camera)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/camera/__init__.py", line 657, in handle
    stream = await camera.handle_async_mjpeg_stream(request)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/mjpeg/camera.py", line 173, in handle_async_mjpeg_stream
    return await async_aiohttp_proxy_web(self.hass, request, stream_coro)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/aiohttp_client.py", line 142, in async_aiohttp_proxy_web
    return await async_aiohttp_proxy_stream(
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/aiohttp_client.py", line 172, in async_aiohttp_proxy_stream
    await response.write(data)
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/web_response.py", line 470, in write
    await self._payload_writer.write(data)
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/http_writer.py", line 107, in write
    self._write(chunk)
  File "/srv/homeassistant/lib/python3.9/site-packages/aiohttp/http_writer.py", line 67, in _write
    raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport

I’ve looked at different blogs (including this one) and github issues but I haven’t found a way to fix the problem.

In addition, I sometimes have authentication errors visible in the logs of HA and my nginx reverse-proxy due to these cameras :

I have tried various settings including setting the cameras to https but have always failed.

If anyone has a solution I’m obviously interested :wink: