home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.67k stars 30.42k forks source link

Onvif camera setup fails, username/password not used in setup URL #34099

Closed abaretta closed 4 years ago

abaretta commented 4 years ago

The problem

Error while setting up onvif platform for camera

Environment

Problem-relevant configuration.yaml

camera:
  - platform: onvif
    host: 192.168.20.133
    port: 10554
    username: !secret dbellusername
    password: !secret dbellpassword

Traceback/Error logs

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 847, in start
    message, payload = await self._protocol.read()  # type: ignore  # noqa
  File "/usr/local/lib/python3.7/site-packages/aiohttp/streams.py", line 591, in read
    await self._waiter
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_proto.py", line 199, in data_received
    messages, upgraded, tail = self._parser.feed_data(data)
  File "aiohttp\_http_parser.pyx", line 523, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadHttpMessage: 400, message='invalid constant string'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/src/homeassistant/homeassistant/components/onvif/camera.py", line 145, in async_setup_platform
    await hass_camera.async_initialize()
  File "/usr/src/homeassistant/homeassistant/components/onvif/camera.py", line 199, in async_initialize
    await self._camera.update_xaddrs()
  File "/usr/local/lib/python3.7/site-packages/onvif/client.py", line 233, in update_xaddrs
    capabilities = await self.devicemgmt.GetCapabilities({'Category': 'All'})
  File "/usr/local/lib/python3.7/site-packages/zeep/asyncio/bindings.py", line 13, in send
    options["address"], envelope, http_headers
  File "/usr/local/lib/python3.7/site-packages/zeep/asyncio/transport.py", line 107, in post_xml
    response = await self.post(address, message, headers)
  File "/usr/local/lib/python3.7/site-packages/zeep/asyncio/transport.py", line 95, in post
    proxy=self.proxy,
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 504, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 852, in start
    message=exc.message, headers=exc.headers) from exc
aiohttp.client_exceptions.ClientResponseError: 400, message='invalid constant string', url='http://192.168.20.133:10554/onvif/device_service

Additional information

It seems the setup URL pointing to the onvif/device_service does not include the username:password. When I include them in the http://192.168.20.133:10554/username:password@onvif/device_service the camera correctly returns the Onvif capabilities:

RTSP/1.0 200 OK Cseq: 0 Date: Sun, Apr 12 2020 15:29:20 GMT Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER

Thanks in advance!

hunterjm commented 4 years ago

The ONVIF client uses digest authentication when connecting to the device service per section 5.12.1 of the ONVIF Core Specification. Either your device is non-conformant, or you have configured the entry incorrectly.

pergolafabio commented 4 years ago

i am having the same error, i use the ONVIF integration, not yaml, so i let it discover or add manually it succeeds, the entity is created, i can even watch my camera live feed in HA , then a few moments later, or if i restart HA , the error below comes, and live feed is gone, and also the entity is gone

2020-06-17 22:51:52 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry C1 - 00626E940744 for onvif
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 847, in start
    message, payload = await self._protocol.read()  # type: ignore  # noqa
  File "/usr/local/lib/python3.7/site-packages/aiohttp/streams.py", line 591, in read
    await self._waiter
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_proto.py", line 199, in data_received
    messages, upgraded, tail = self._parser.feed_data(data)
  File "aiohttp\_http_parser.pyx", line 523, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadHttpMessage: 400, message='invalid constant string'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 217, in async_setup
    hass, self
  File "/usr/src/homeassistant/homeassistant/components/onvif/__init__.py", line 73, in async_setup_entry
    if not await device.async_setup():
  File "/usr/src/homeassistant/homeassistant/components/onvif/device.py", line 97, in async_setup
    self.capabilities = await self.async_get_capabilities()
  File "/usr/src/homeassistant/homeassistant/components/onvif/device.py", line 246, in async_get_capabilities
    event_capabilities = await event_service.GetServiceCapabilities()
  File "/usr/local/lib/python3.7/site-packages/zeep/asyncio/bindings.py", line 13, in send
    options["address"], envelope, http_headers
  File "/usr/local/lib/python3.7/site-packages/zeep/asyncio/transport.py", line 107, in post_xml
    response = await self.post(address, message, headers)
  File "/usr/local/lib/python3.7/site-packages/zeep/asyncio/transport.py", line 95, in post
    proxy=self.proxy,
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 504, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 852, in start
    message=exc.message, headers=exc.headers) from exc
aiohttp.client_exceptions.ClientResponseError: 400, message='invalid constant string', url='http://192.168.0.38:888/onvif/device_service
pergolafabio commented 4 years ago

and running 111.3 :)

stale[bot] commented 4 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.