Problem with UBUS Device Tracker

Hello,
I have router where is OpenWRT.
On device_trackers.yaml I have:

  • platform: luci
    host:
    username: root
    password:
And I can't run this, I have this error:

Error setting up platform luci
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 326, in connect
    ssl_context=context)
  File "/usr/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 329, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/usr/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='149.194.61.1', port=443): Max retries exceeded with url: /cgi-bin/luci/rpc/auth (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 162, in async_setup_platform
    platform.get_scanner, hass, {DOMAIN: p_config})
  File "/usr/lib/python3.6/asyncio/futures.py", line 332, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/luci.py", line 37, in get_scanner
    scanner = LuciDeviceScanner(config[DOMAIN])
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/luci.py", line 54, in __init__
    self.refresh_token()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/luci.py", line 60, in refresh_token
    self.token = _get_token(self.host, self.username, self.password)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/luci.py", line 155, in _get_token
    return _req_json_rpc(url, 'login', username, password)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/luci.py", line 123, in _req_json_rpc
    res = requests.post(url, data=data, timeout=5, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 640, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 640, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 218, in resolve_redirects
    **adapter_kwargs
  File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 506, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='149.194.61.1', port=443): Max retries exceeded with url: /cgi-bin/luci/rpc/auth (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)'),))

How can I resolve this?

are you trying to connect to your router though ssl? You shouldn’t have to, it should just be localhost

yes I have SSL on openwrt. I have installed luci-ssl

According to the docs, you need a work around if you are using SSL:

This component requires a workaround when using luci with HTTPS and a self-signed certificate:

I was trying but when I enter “update-ca-certificates” I have error:
sudo: update-ca-certificates: command not found

If you are running hass.io, that method won’t work and you’ll need to contact the developers or open the issue back up

Okay, another thing. I leave luci.
Now I have UBUS.

I was doing everything from: https://home-assistant.io/components/device_tracker.ubus/
When I write: " ubus list | grep file " I have Output: file

Now, it not showing SSL problem. I have refuse it.
But now I have this error:

Thu Mar 08 2018 14:47:22 GMT+0100 (CET)
 
Error setting up platform ubus
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 162, in async_setup_platform
    platform.get_scanner, hass, {DOMAIN: p_config})
  File "/usr/lib/python3.6/asyncio/futures.py", line 332, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/device_tracker/ubus.py", line 42, in get_scanner
    scanner = DnsmasqUbusDeviceScanner(config[DOMAIN])
  File "/config/custom_components/device_tracker/ubus.py", line 145, in __init__
    super(DnsmasqUbusDeviceScanner, self).__init__(config)
  File "/config/custom_components/device_tracker/ubus.py", line 84, in __init__
    self.url, self.username, self.password)
  File "/config/custom_components/device_tracker/ubus.py", line 230, in _get_session_id
    return res["ubus_rpc_session"]
TypeError: 'NoneType' object is not subscriptable

Somebody help me ?

1 Like

I have the same problem…

Error setting up platform ubus
Traceback (most recent call last):
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/device_tracker/init.py”, line 181, in async_setup_platform
platform.get_scanner, hass, {DOMAIN: p_config})
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/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/device_tracker/ubus.py”, line 43, in get_scanner
scanner = DnsmasqUbusDeviceScanner(config[DOMAIN])
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/device_tracker/ubus.py”, line 148, in init
super(DnsmasqUbusDeviceScanner, self).init(config)
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/device_tracker/ubus.py”, line 87, in init
self.url, self.username, self.password)
File “/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/components/device_tracker/ubus.py”, line 233, in _get_session_id
return res[“ubus_rpc_session”]
TypeError: ‘NoneType’ object is not subscriptable

do you solove it?

Are you using Hassio? If the answer is yes, you do not have a work around.

no,i use the homeassistant on ubuntu

Then the solution is here:

use this method?

I . Copy your CA cert (make sure file extension is .crt) to /usr/share/ca-certificates/
2. $ sudo update-ca-certificates (make sure you see “1 added” in the output
3. Set environment variable REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt when you starts home assistant.

The “requests” library used for making HTTPS requests to openwrt seems to bundle its own CA bundle by default and this should override the behavior.

thank you

I believe so, I’ve never done it. Just found it in that thread.

but my problem is not showing SSL problem…

Did you follow the installation guide for the RPC package for OpenWRT?

Namely:

Before this scanner can be used you have to install the ubus RPC package on OpenWRT:

opkg install rpcd-mod-file
And create a read-only user to be used by setting up the ACL file /usr/share/rpcd/acl.d/user.json.

{
  "user": {
    "description": "Read only user access role",
    "read": {
      "ubus": {
        "*": [ "*" ]
      },
      "uci": [ "*" ]
    },
    "write": {}
  }
}
Restart the services.

# /etc/init.d/rpcd restart && /etc/init.d/uhttpd restart
Check if the file namespaces is registered with the RPC server.

# ubus list | grep file
file

yes ,i have do that

I’ve been struggling with this since upgrading to a newer version of OpenWrt. For me what solved it was installing opkg install uhttpd-mod-ubus. I came to this conclusion because the POST to /ubus on my router would return a 404.

It would be a big improvement in troubleshootability of this code if a non 2xx return of the RPC call would be logged as an error and not some exception that something is NoneType somewhere downstream.

1 Like

I’ve been struggling with this since upgrading to a newer version of OpenWrt. For me what solved it was installing opkg install uhttpd-mod-ubus.

I have the same problem now after upgrading Open WRT from 17.x to 18.x. How did you exactly solve it? Just installing utthpd-mod-ubus? I tried that but without any result. Did you change or tweak anything else?