49.0 and Amcrest cameras

What is your setup? My is working using rtsp and ffmpeg

I did manage to get it working using rtsp and ffmpeg but was just curious why this suddenly stopped working. My setup was:

configuration.yaml

amcrest:
  - host: 192.0.0.0
    port: 80
    username: !username
    password: !password
    stream_source: snapshot

camera.yaml

- platform: amcrest

I do’t get any errors with the above but no picture.

Amcrest suddenly stopped working for me when I upgraded to 0.52.1.

amcrest:
  - host: 192.168.1.125
    username: admin
    password: !secret amcrest_password
  - host: 192.168.1.102
    username: admin
    password: !secret amcrest_password

haven’t changed my config since uprade and it was working on 0.51.2. Here is the error:

2017-09-05 17:40:52 ERROR (MainThread) [homeassistant.setup] Error during setup of component amcrest
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/amcrest/http.py", line 82, in _generate_token
    req.raise_for_status()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/requests/models.py", line 928, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: http://192.168.1.125:80/cgi-bin/magicBox.cgi?action=getMachineName

For me as well.

1 Like

Same problem as @jglow… I’m on a fresh install of 0.58.1 (which brings in amcrest 1.2.1)

Getting the same error:

Dec 03 20:47:14 hawkpi hass[12697]: 2017-12-03 20:47:14 ERROR (MainThread) [homeassistant.setup] Error during setup of component amcrest
Dec 03 20:47:14 hawkpi hass[12697]: Traceback (most recent call last):
Dec 03 20:47:14 hawkpi hass[12697]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py", line 193, in _async_setup_component
Dec 03 20:47:14 hawkpi hass[12697]:     component.setup, hass, processed_config)
Dec 03 20:47:14 hawkpi hass[12697]:   File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
Dec 03 20:47:14 hawkpi hass[12697]:     yield self  # This tells Task to wait for completion.
Dec 03 20:47:14 hawkpi hass[12697]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
Dec 03 20:47:14 hawkpi hass[12697]:     future.result()
Dec 03 20:47:14 hawkpi hass[12697]:   File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
Dec 03 20:47:14 hawkpi hass[12697]:     raise self._exception
Dec 03 20:47:14 hawkpi hass[12697]:   File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
Dec 03 20:47:14 hawkpi hass[12697]:     result = self.fn(*self.args, **self.kwargs)
Dec 03 20:47:14 hawkpi hass[12697]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/amcrest.py", line 98, in setup
Dec 03 20:47:14 hawkpi hass[12697]:     device.get(CONF_PASSWORD)).camera
Dec 03 20:47:14 hawkpi hass[12697]:   File "/srv/homeassistant/lib/python3.5/site-packages/amcrest/__init__.py", line 32, in __init__
Dec 03 20:47:14 hawkpi hass[12697]:     timeout_protocol=timeout_protocol
Dec 03 20:47:14 hawkpi hass[12697]:   File "/srv/homeassistant/lib/python3.5/site-packages/amcrest/http.py", line 68, in __init__
Dec 03 20:47:14 hawkpi hass[12697]:     self._set_name()
Dec 03 20:47:14 hawkpi hass[12697]:   File "/srv/homeassistant/lib/python3.5/site-packages/amcrest/http.py", line 101, in _set_name
Dec 03 20:47:14 hawkpi hass[12697]:     self._name = pretty(self.machine_name)
Dec 03 20:47:14 hawkpi hass[12697]:   File "/srv/homeassistant/lib/python3.5/site-packages/amcrest/system.py", line 100, in machine_name
Dec 03 20:47:14 hawkpi hass[12697]:     'magicBox.cgi?action=getMachineName'
Dec 03 20:47:14 hawkpi hass[12697]:   File "/srv/homeassistant/lib/python3.5/site-packages/amcrest/http.py", line 155, in command
Dec 03 20:47:14 hawkpi hass[12697]:     resp.raise_for_status()
Dec 03 20:47:14 hawkpi hass[12697]:   File "/srv/homeassistant/lib/python3.5/site-packages/requests/models.py", line 935, in raise_for_status
Dec 03 20:47:14 hawkpi hass[12697]:     raise HTTPError(http_error_msg, response=self)
Dec 03 20:47:14 hawkpi hass[12697]: requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: http://192.168.1.131:80/cgi-bin/magicBox.cgi?action=getMachineName

It’s almost as if the try: / except: block in the _generate_token() function isn’t excepting to digest auth if basic auth fails. My Amcrest camera is an IP2M-841B running firmware 2.520.AC00.18.R, Build Date: 2017-06-29, which requires digest auth.

If I hack the http.py code to remove the try/except for basic/digest auth and force digest auth directly, I get past the initial error above and the camera snapshot is viewable in HA. But then whenever I try to view the stream by clicking on it, I see a similar error in the log as if it has not been authorized:

...
Dec 03 20:53:53 hawkpi hass[12910]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/amcrest.py", line 67, in camera_image
Dec 03 20:53:53 hawkpi hass[12910]:     response = self._camera.snapshot(channel=self._resolution)
Dec 03 20:53:53 hawkpi hass[12910]:   File "/srv/homeassistant/lib/python3.5/site-packages/amcrest/snapshot.py", line 48, in snapshot
Dec 03 20:53:53 hawkpi hass[12910]:     timeout_cmd=timeout
Dec 03 20:53:53 hawkpi hass[12910]:   File "/srv/homeassistant/lib/python3.5/site-packages/amcrest/http.py", line 147, in command
Dec 03 20:53:53 hawkpi hass[12910]:     resp.raise_for_status()
Dec 03 20:53:53 hawkpi hass[12910]:   File "/srv/homeassistant/lib/python3.5/site-packages/requests/models.py", line 935, in raise_for_status
Dec 03 20:53:53 hawkpi hass[12910]:     raise HTTPError(http_error_msg, response=self)
Dec 03 20:53:53 hawkpi hass[12910]: requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: http://192.168.1.131:80/cgi-bin/snapshot.cgi?channel=1

@tchellomello - do you have any ideas or suggestions?

Thanks in advance!

I just purchased an Amcrest camera to use with HA, and am getting the same error as everybody else:

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: http://192.168.x.x:80/cgi-bin/magicBox.cgi?action=getMachineName

My configuration.yaml is:

# amcrest component (security cam)
amcrest:
  - host: 192.168.x.x
    username: admin
    password: !secret amcrest_password
    sensors:
      - motion_detector
      - sdcard

camera:
  - platform: amcrest

UPDATE: Nevermind, I’m a moron. It was a wrong password…