rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
369 stars 71 forks source link

Port could not be cast to integer value #362

Open lkoniecki opened 1 month ago

lkoniecki commented 1 month ago

Parsing the url, if the camera password contains special characters does not work. Looks like the logic of getting the port is wrong.

Exception in the HA log:

2024-06-11 16:25:03.639 ERROR (stream_worker) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/stream/worker.py", line 516, in stream_worker
    container = av.open(source, options=pyav_options, timeout=SOURCE_TIMEOUT)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "av/container/core.pyx", line 398, in av.container.core.open
  File "av/container/core.pyx", line 270, in av.container.core.Container.__cinit__
  File "av/container/core.pyx", line 290, in av.container.core.Container.err_check
  File "av/error.pyx", line 336, in av.error.err_check
av.error.ValueError: [Errno 22] Invalid argument: 'rtsp://user:pass@ip:554/cam/realmonitor?channel=3&subtype=0'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 191, in __new__
    port = val.port
           ^^^^^^^^
  File "/usr/local/lib/python3.12/urllib/parse.py", line 182, in port
    raise ValueError(f"Port could not be cast to integer value as {port!r}")
ValueError: Port could not be cast to integer value as 'pass'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/src/homeassistant/homeassistant/components/stream/__init__.py", line 438, in _run_worker
    stream_worker(
  File "/usr/src/homeassistant/homeassistant/components/stream/worker.py", line 520, in stream_worker
    f" {redact_credentials(str(source))}"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/stream/__init__.py", line 100, in redact_credentials
    yurl = URL(url)
           ^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/yarl/_url.py", line 193, in __new__
    raise ValueError(
ValueError: Invalid URL: port can't be converted to integer

See:

Port could not be cast to integer value as 'pass'

Instead of getting the 554 port, it got password value from the URL.