I was working on extending a sensor for Home Assistant to get battery level for the cameras, then I hit the problem below when pulling the cameras to get the battery level:
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/site-packages/pyarlo/base_station.py", line 40, in thread_function
data = self._session.query(url, method='GET', raw=True, stream=True)
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/site-packages/pyarlo/__init__.py", line 141, in query
req.raise_for_status()
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/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: https://arlo.netgear.com/hmsweb/client/subscribe?token=<REDACTED>
2017-07-07 00:03:22 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.last_front_door_lateral, old_state=None, new_state=<state sensor.last_front_door_lateral=07-06-2017 08:09:28; attribution=Data provided by arlo.netgear.com, brand=Netgear Arlo, model=VMC3030, friendly_name=Last Front Door Lateral, icon=mdi:run-fast @ 2017-07-07T00:03:22.768137-04:00>>
2017-07-07 00:03:23 INFO (SyncWorker_6) [pyarlo.base_station] Action body: {'action': 'get', 'from': '<REDACTED>_web', 'properties': None, 'publishResponse': 'false', 'resource': 'cameras', 'to': '48914CXXXXX', 'transId': '<REDACTED>'}
2017-07-07 00:03:23 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2017-07-07 00:03:25 INFO (SyncWorker_12) [pyarlo.base_station] Action body: {'action': 'set', 'from': '<REDACTED>_web', 'properties': {'devices': ['48914CXXXX']}, 'publishResponse': 'false', 'resource': 'subscriptions/<REDACTED>_web', 'to': '48914CXXXXX', 'transId': '<REDACTED>'}
Exception in thread Thread-5:
Traceback (most recent call last):
File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/site-packages/pyarlo/base_station.py", line 40, in thread_function
data = self._session.query(url, method='GET', raw=True, stream=True)
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/site-packages/pyarlo/__init__.py", line 141, in query
req.raise_for_status()
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/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: https://arlo.netgear.com/hmsweb/client/subscribe?token=<REDACTED>
2017-07-07 00:03:26 INFO (SyncWorker_12) [pyarlo.base_station] Action body: {'action': 'get', 'from': '<REDACTED>_web', 'properties': None, 'publishResponse': 'false', 'resource': 'cameras', 'to': '48914CXXXXX', 'transId': '<REDACTED>'}
2017-07-07 00:03:26 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform arlo is taking over 10 seconds.
2017-07-07 00:03:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib64/python3.6/asyncio/tasks.py", line 181, in _step
result = coro.throw(exc)
File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 381, in async_process_entity
new_entity, self, update_before_add=update_before_add
File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 212, in async_add_entity
yield from self.hass.async_add_job(entity.update)
File "/usr/lib64/python3.6/asyncio/futures.py", line 331, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib64/python3.6/asyncio/tasks.py", line 244, in _wakeup
future.result()
File "/usr/lib64/python3.6/asyncio/futures.py", line 244, in result
raise self._exception
File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/mdemello/devel/home-assistant/homeassistant/components/sensor/arlo.py", line 104, in update
self._state = self._data.get_battery_level
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/site-packages/pyarlo/camera.py", line 132, in get_battery_level
return base.get_camera_battery_level[self.device_id]
TypeError: 'NoneType' object is not subscriptable
2017-07-07 00:03:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib64/python3.6/asyncio/tasks.py", line 181, in _step
result = coro.throw(exc)
File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 381, in async_process_entity
new_entity, self, update_before_add=update_before_add
File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 212, in async_add_entity
yield from self.hass.async_add_job(entity.update)
File "/usr/lib64/python3.6/asyncio/futures.py", line 331, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib64/python3.6/asyncio/tasks.py", line 244, in _wakeup
future.result()
File "/usr/lib64/python3.6/asyncio/futures.py", line 244, in result
raise self._exception
File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/mdemello/devel/home-assistant/homeassistant/components/sensor/arlo.py", line 104, in update
self._state = self._data.get_battery_level
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/site-packages/pyarlo/camera.py", line 132, in get_battery_level
return base.get_camera_battery_level[self.device_id]
TypeError: 'NoneType' object is not subscriptable
2017-07-07 00:03:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib64/python3.6/asyncio/tasks.py", line 181, in _step
result = coro.throw(exc)
File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 381, in async_process_entity
new_entity, self, update_before_add=update_before_add
File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 212, in async_add_entity
yield from self.hass.async_add_job(entity.update)
File "/usr/lib64/python3.6/asyncio/futures.py", line 331, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib64/python3.6/asyncio/tasks.py", line 244, in _wakeup
future.result()
File "/usr/lib64/python3.6/asyncio/futures.py", line 244, in result
raise self._exception
File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/mdemello/devel/home-assistant/homeassistant/components/sensor/arlo.py", line 104, in update
self._state = self._data.get_battery_level
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/site-packages/pyarlo/camera.py", line 132, in get_battery_level
return base.get_camera_battery_level[self.device_id]
TypeError: 'NoneType' object is not subscriptable
2017-07-07 00:03:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib64/python3.6/asyncio/tasks.py", line 181, in _step
result = coro.throw(exc)
File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 381, in async_process_entity
new_entity, self, update_before_add=update_before_add
File "/home/mdemello/devel/home-assistant/homeassistant/helpers/entity_component.py", line 212, in async_add_entity
yield from self.hass.async_add_job(entity.update)
File "/usr/lib64/python3.6/asyncio/futures.py", line 331, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib64/python3.6/asyncio/tasks.py", line 244, in _wakeup
future.result()
File "/usr/lib64/python3.6/asyncio/futures.py", line 244, in result
raise self._exception
File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/mdemello/devel/home-assistant/homeassistant/components/sensor/arlo.py", line 104, in update
self._state = self._data.get_battery_level
File "/home/mdemello/.virtualenvs/ha-py36/lib/python3.6/site-packages/pyarlo/camera.py", line 132, in get_battery_level
return base.get_camera_battery_level[self.device_id]
TypeError: 'NoneType' object is not subscriptable
If I leave it running, due to multiple requests being executed on the Thread(), eventually all sensors will get updated
I believe the issue might be happening for any requests inside of the Thread().
2017-07-07 01:12:31 WARNING (Thread-3) [r2017-07-07 01:12:28 WARNING (SyncWorker_8) [requests.packages.urllib3.connectionpool] Connection pool is full, discarding connection: arlo.netgear.com
equests.packages.urllib3.connectionpool] Connection pool is full, discarding connection: arlo.netgear.com
But besides extending the pool, what else should we do to avoid the 401 requests? Maybe should we modify the Thread() code to make sure to just request its one component?