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
73.45k stars 30.69k forks source link

Synology cameras won't load when using non-admin DSM account #9908

Closed mbrrg closed 6 years ago

mbrrg commented 7 years ago

Home Assistant release (hass --version): 0.55.2 (official Docker image) Python release (python3 --version): 3.6 (Docker) Component/platform: camera/synology Description of problem: After upgrade to 0.55.2 (from 0.53 or so) my Synology cameras won't load due to some authentication problem in the py-synology library (speculation). Loading fails if I specify a Synology user account with limited permissions to only access SurveillanceStation but works fine if I specify the credentials of my DiskStation admin user which has access to everything.

Expected: Synology cameras should work as normal also for a user account with limited (but valid) access rights.

Problem-relevant configuration.yaml entries and steps to reproduce:

camera:
  - platform: synology
    url: https://xxxxxxxxx.localdomain:5001
    username: homeassistant
    password: xxxxxxxxxxxx
    timeout: 15
    verify_ssl: False

Traceback (if applicable):

2017-10-16 20:37:55 ERROR (MainThread) [homeassistant.components.camera.synology] Error when initializing SurveillanceStation
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/camera/synology.py", line 54, in async_setup_platform
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/synology/surveillance_station.py", line 9, in __init__
    self._api = Api(url, username, password, timeout, verify_ssl)
  File "/usr/local/lib/python3.6/site-packages/synology/api.py", line 56, in __init__
    self._initialize_api_sid()
  File "/usr/local/lib/python3.6/site-packages/synology/api.py", line 82, in _initialize_api_sid
    response = self._get_json(api['url'], payload)
  File "/usr/local/lib/python3.6/site-packages/synology/api.py", line 191, in _get_json
    raise ValueError('Invalid or failed response', content)
ValueError: ('Invalid or failed response', {'error': {'code': 400}, 'success': False})
snjoetw commented 7 years ago

I'm using non-admin account and I'm able to use synology camera component.

Can you check Control Panel -> Users -> Select your non-admin user and click Edit -> Applications

Do you see Surveillance Station is allowed?

jradwan commented 7 years ago

I'm having the same issue. And my non-admin account does have permissions to Surveillance Station. This was working until 0.55.x.

image

snjoetw commented 7 years ago

That’s weird, I’ll have another look tonight. But there wasn’t any change made related to how authentication work

jeffharrell commented 7 years ago

I'm seeing this issue as well. 400 API response from the camera component. If I don't change the user/pass, but change the account on my synology to be an admin it works as expected.

mbrrg commented 7 years ago

@snjoetw Yes it's configured to allow SurveillanceStation. Changing between manager/spectator also doesn't help. I will try to figure out exactly which call it is that fails tonight, the problem is reproducible using the Github code example for py-synology.

mbrrg commented 7 years ago

There was a difference small difference between how the auth call was made earlier, the "application session name" parameter that specifies the login scope was missing. This meant that access to DiskStation was necessary to be able to authenticate. I have submitted an issue and a PR for py-synology: https://github.com/snjoetw/py-synology/issues/1

snjoetw commented 7 years ago

Thanks @mbrrg, I just released py-synology-0.1.5 (https://pypi.python.org/pypi/py-synology/0.1.5)

Do you want to update home-assistant to uptake latest version or I can do it, just let me know

arsaboo commented 7 years ago

@snjoetw Created a PR https://github.com/home-assistant/home-assistant/pull/9932

snjoetw commented 7 years ago

Thanks @arsaboo👍

mvonh commented 7 years ago

I have this issue too, I'm using two factory authentication, but only for admin access. Just upgraded to .56 still no cameras. Did this update make it into .56, in not how can I manual update py-synology? Promoting my camera user to Admin solves it. Thank for the work on this platform btw.

jradwan commented 7 years ago

Upgraded to 0.56 and my Synology cameras are working again (non-admin user, like in 0.54). But now my Nest cams are broken (issue #10018). 😦

DavidDeSloovere commented 7 years ago

Synology fixed for me.

snjoetw commented 7 years ago

@mbrrg is this still an issue?

mbrrg commented 7 years ago

I'm afraid it is still an issue for me @snjoetw. The weird thing is that running the following snippet inside the Docker container works fine:

from synology.surveillance_station import SurveillanceStation
import logging
import sys

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

api_url = 'https://xxxxxxxxxx.localdomain:5001'
username = 'homeassistant'
password = 'xxxxx'
verify_ssl = False
timeout = 15

surveillance = SurveillanceStation(api_url, username, password, verify_ssl=verify_ssl, timeout=timeout)
cameras = surveillance.get_all_cameras()
print([c.camera_id for c in cameras])

...but I still get the same error in the Home-Assistant log and the component doesn't load. I will see if I can get some time to troubleshoot this further during the weekend.

JIOB commented 7 years ago

Also still an issue for me .

HASS: 56.2

2017-11-03 07:16:51 ERROR (MainThread) [homeassistant.components.camera.synology] Error when initializing SurveillanceStation
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/camera/synology.py", line 54, in async_setup_platform
    timeout=timeout
  File "/config/deps/lib/python3.6/site-packages/synology/surveillance_station.py", line 9, in __init__
    self._api = Api(url, username, password, timeout, verify_ssl)
  File "/config/deps/lib/python3.6/site-packages/synology/api.py", line 56, in __init__
    self._initialize_api_sid()
  File "/config/deps/lib/python3.6/site-packages/synology/api.py", line 82, in _initialize_api_sid
    response = self._get_json(api['url'], payload)
  File "/config/deps/lib/python3.6/site-packages/synology/api.py", line 191, in _get_json
    raise ValueError('Invalid or failed response', content)
ValueError: ('Invalid or failed response', {'error': {'code': 400}, 'success': False})
mbrrg commented 7 years ago

It has started working for me again with the limited user and without any (seemingly relevant) changes to the HA configuration. I've restarted the Synology today though, could have been some temporary hickup...

JIOB commented 6 years ago

Am i the only one still experiencing this in 58.1?

mbrrg commented 6 years ago

Nope, it stopped working for me after upgrade to 58.1 the other day @tryingwebguy .

xiti commented 6 years ago

Had the same problem with a brand new NVR216.

I was using special chars like % and $ in my 8-chars long password for a spectator user, I made a new one of 16 characters without special chars, and it seems to work fine now. Looks like Surveillance Station doesn't support special passwords...

Finally 'solved' this shitty problem, so annoying.

mbrrg commented 6 years ago

This works for me as well now. The culprit was an old version of py-synology that for some reason was still around in my config/deps directory. Will remove the deps directory when I switch Docker images from now on.

DavidDeSloovere commented 6 years ago

I have noticed that I need to restart HA after installing an update on the Synology and I'm not getting the cams to show images.