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.19k stars 30.57k forks source link

"authentication: digest" with RESTful Binary Sensor causes exception "AttributeError: '_thread._local' object has no attribute 'pos'" #13524

Closed pnbruckner closed 5 years ago

pnbruckner commented 6 years ago

Home Assistant release with the issue:

0.65.6

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.):

Raspbian Stretch Lite on Raspberry Pi 3B

Component/platform:

https://www.home-assistant.io/components/binary_sensor.rest/

Description of problem:

Using the RESTful Binary Sensor to retrieve status from my Amcrest IP2M-841 camera. This camera requires digest authentication. However, when setting "authentication: digest" in configuration.yaml, the result is an exception.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

binary_sensor:
  - platform: rest
    resource: http://[IP]:[port]/cgi-bin/alarm.cgi?action=getOutState
    username: [username]
    password: !secret lr_ipc_password
    authentication: digest
    name: LR IPC Motion
    device_class: motion
    value_template: '{{ value.count("1") }}'

Traceback (if applicable):

2018-03-24 14:35:06 ERROR (MainThread) [homeassistant.components.binary_sensor] rest: Error on device update!
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 188, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 327, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/binary_sensor/rest.py", line 126, in update
    self.rest.update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/rest.py", line 176, in update
    self._request, timeout=10, verify=self._verify_ssl)
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/sessions.py", line 625, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/requests/auth.py", line 235, in handle_401
    if self._thread_local.pos is not None:
AttributeError: '_thread._local' object has no attribute 'pos'

Additional information:

https://community.home-assistant.io/t/authentication-digest-with-restful-binary-sensor/48122

Using the Command Line Binary Sensor instead it works just fine using "curl --digest ..."

balloobbot commented 6 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 :+1:

mannkind commented 6 years ago

FWIW I just ran into this issue as well with a foscam ip camera that requires digest authentication to get the status of the alarm.

Home Assistant release with the issue: 0.70.1

Last working Home Assistant release (if known): Unknown

Operating environment (Hass.io/Docker/Windows/etc.): Docker; Linux; amd64

dynasticorpheus commented 6 years ago

Same here trying to extract temperature / humidity information from baby-camera using digest authentication

Home Assistant release with the issue: 0.78.3

Last working Home Assistant release (if known): Unknown

Operating environment (Hass.io/Docker/Windows/etc.): Linux; amd64

balloobbot commented 5 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 :+1:

balloobbot commented 5 years ago

This issue will be auto-closed because there hasn't been any activity for a few months. Feel free to open a new one if you still experience this problem đź‘Ť

epenet commented 5 years ago

Can this be re-opened? It is still an issue and preventing me from using the Scrape sensor in 0.97.2...

Configuration.yaml:

sensor:
  - platform: scrape
    resource: http://xxx.xxx.xxx.xxx/statsifcwan.html?Rtabhead=Status
    username: user
    password: !secret password
    authentication: digest
    name: ADSL Upstream Attenuation
    select: 'td'
    index: 71
    value_template: '{{ value.split(" ")[0] }}'
    unit_of_measurement: db

Traceback (if applicable):

2019-08-27 02:32:22 ERROR (MainThread) [homeassistant.components.sensor] scrape: Error on device update!
Traceback (most recent call last):
  File "/home/pi/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 291, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/home/pi/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 419, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/pi/homeassistant/lib/python3.7/site-packages/homeassistant/components/scrape/sensor.py", line 122, in update
    self.rest.update()
  File "/home/pi/homeassistant/lib/python3.7/site-packages/homeassistant/components/rest/sensor.py", line 226, in update
    self._request, timeout=self._timeout, verify=self._verify_ssl
  File "/home/pi/homeassistant/lib/python3.7/site-packages/requests/sessions.py", line 653, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "/home/pi/homeassistant/lib/python3.7/site-packages/requests/hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "/home/pi/homeassistant/lib/python3.7/site-packages/requests/auth.py", line 247, in handle_401
    if self._thread_local.pos is not None:
AttributeError: '_thread._local' object has no attribute 'pos'
christianschneider89 commented 4 years ago

Same here with 0.114.4. Please reopen. The dishwasher needs to authenticate with digest. Basic doesn't work.