HABApp 1.0.6 with OpenHAB 3.4: no access to rest API

I have updated my development system on a raspberry pi v3 from OH 3.4M5 to OH 3.4.0 and I am unable to have HABApp working. Previously the system was on OH 3.4M1.
The trouble is that HABApp is unable to access to the rest API. The log file is filled with status 401 as follows

2022-12-24 07:54:30.690 [INFO ] [HABApp                              ] - HABApp Version 1.0.6
2022-12-24 07:54:30.796 [INFO ] [HABApp.Config                       ] - Textual thing config disabled! Folder /etc/openhab/habapp/params does not exist!
2022-12-24 07:54:30.797 [INFO ] [HABApp.Config                       ] - Manual thing configuration disabled! Folder /etc/openhab/habapp/config does not exist!
2022-12-24 07:54:30.811 [INFO ] [HABApp.mqtt.connection              ] - MQTT disabled
2022-12-24 07:54:31.743 [INFO ] [HABApp.openhab.connection           ] - Connected to OpenHAB version 3.4.0 (Release Build)
2022-12-24 07:54:31.771 [WARN ] [HABApp.openhab.connection           ] - Status 401 for GET http://localhost:8080/rest/systeminfo
2022-12-24 07:54:31.774 [INFO ] [HABApp.openhab.connection           ] - Waiting for openHAB startup to be complete
2022-12-24 07:54:32.809 [WARN ] [HABApp.openhab.connection           ] - Status 401 for GET http://localhost:8080/rest/systeminfo 20

I have read that this may be related to authentication problems and I have set the option Allow basic authentication under the API security setting.

From the browser I get a similar error. When I type on the address bar of chrome

http://192.168.27.82:8080/rest/systeminfo

The output is

{"error":{"message":"Authentication required","http-code":401}}

If I add username and password to the https query nothing changes (I tried also with the edge browser). If I try with a simpler different query

http://192.168.27.82:8080/rest

it gives some result in both browsers

{"version":"5","locale":"en_US","measurementSystem":"SI","runtimeInfo":{"version":"3.4.0","buildString":"Release Build"},"links":[{"type":"profile-types","url":"https://192.168.27.82:8443/rest/profile-types"},{"type":"uuid","url":"https://192.168.27.82:8443/rest/uuid"},{"type":"spec","url":"https://192.168.27.82:8443/rest/spec"},{"type":"logging","url":"https://192.168.27.82:8443/rest/logging"},{"type":"ui","url":"https://192.168.27.82:8443/rest/ui"},{"type":"events","url":"https://192.168.27.82:8443/rest/events"},{"type":"thing-types","url":"https://192.168.27.82:8443/rest/thing-types"},{"type":"channel-types","url":"https://192.168.27.82:8443/rest/channel-types"},{"type":"config-descriptions","url":"https://192.168.27.82:8443/rest/config-descriptions"},{"type":"links","url":"https://192.168.27.82:8443/rest/links"},{"type":"sitemaps","url":"https://192.168.27.82:8443/rest/sitemaps"},{"type":"transformations","url":"https://192.168.27.82:8443/rest/transformations"},{"type":"discovery","url":"https://192.168.27.82:8443/rest/discovery"},{"type":"persistence","url":"https://192.168.27.82:8443/rest/persistence"},{"type":"systeminfo","url":"https://192.168.27.82:8443/rest/systeminfo"},{"type":"addons","url":"https://192.168.27.82:8443/rest/addons"},{"type":"items","url":"https://192.168.27.82:8443/rest/items"},{"type":"audio","url":"https://192.168.27.82:8443/rest/audio"},{"type":"inbox","url":"https://192.168.27.82:8443/rest/inbox"},{"type":"bindings","url":"https://192.168.27.82:8443/rest/bindings"},{"type":"voice","url":"https://192.168.27.82:8443/rest/voice"},{"type":"things","url":"https://192.168.27.82:8443/rest/things"},{"type":"iconsets","url":"https://192.168.27.82:8443/rest/iconsets"},{"type":"templates","url":"https://192.168.27.82:8443/rest/templates"},{"type":"module-types","url":"https://192.168.27.82:8443/rest/module-types"},{"type":"services","url":"https://192.168.27.82:8443/rest/services"},{"type":"auth","url":"https://192.168.27.82:8443/rest/auth"},{"type":"rules","url":"https://192.168.27.82:8443/rest/rules"}]}

Note that if I perform the systeminfo query from the API explorer it obviously works, and it gives

{
  "systemInfo": {
    "configFolder": "/etc/openhab",
    "userdataFolder": "/var/lib/openhab",
    "logFolder": "/var/log/openhab",
    "javaVersion": "11.0.16",
    "javaVendor": "Raspbian",
    "osName": "Linux",
    "osVersion": "5.15.76-v7+",
    "osArchitecture": "arm",
    "availableProcessors": 4,
    "freeMemory": 123817024,
    "totalMemory": 194904064,
    "startLevel": 100
  }
}

I have tried to clear openhab cache, restart openhab, reboot, uninstall and re-install habapp from openhabian-config but the behavior is always the same.

The only thing that I have not tried is to completely restart from scratch from a new openhabian image.

Is this an issue related to some change in 3.4 (possibly introduced before milestone 5)?

Thank you for your attention
Lionello

The same error remains even when starting from scratch with openhabian image 1.7.5 and installing habapp from openhabian-config

Let me also point out that the installation from openhabian-config fails in generating the directory rules inside the habapp folder, so that i had to manually create that folder and restart habapp

2022-12-24 09:43:24.626 [INFO ] [HABApp                              ] - HABApp Version 1.0.6
2022-12-24 09:43:24.903 [WARN ] [HABApp.Config                       ] - Folder for rules files does not exist: rules
2022-12-24 09:43:27.507 [ERROR] [HABApp                              ] - Error [Errno 13] Permission denied: 'rules' in Runtime.start:
2022-12-24 09:43:27.508 [ERROR] [HABApp                              ] - --------------------------------------------------------------------------------
2022-12-24 09:43:27.508 [ERROR] [HABApp                              ] - Traceback (most recent call last):
2022-12-24 09:43:27.509 [ERROR] [HABApp                              ] -   File "/opt/habapp/lib/python3.9/site-packages/HABApp/runtime/runtime.py", line 40, in start
2022-12-24 09:43:27.509 [ERROR] [HABApp                              ] -     HABApp.config.load_config(config_folder)
2022-12-24 09:43:27.509 [ERROR] [HABApp                              ] -   File "/opt/habapp/lib/python3.9/site-packages/HABApp/config/loader.py", line 36, in load_config
2022-12-24 09:43:27.510 [ERROR] [HABApp                              ] -     load_habapp_cfg(do_print=not loaded_logging)
2022-12-24 09:43:27.510 [ERROR] [HABApp                              ] -   File "/opt/habapp/lib/python3.9/site-packages/HABApp/config/loader.py", line 79, in load_habapp_cfg
2022-12-24 09:43:27.510 [ERROR] [HABApp                              ] -     CONFIG.directories.create_folders()
2022-12-24 09:43:27.510 [ERROR] [HABApp                              ] -   File "/opt/habapp/lib/python3.9/site-packages/HABApp/config/models/directories.py", line 49, in create_folders
2022-12-24 09:43:27.511 [ERROR] [HABApp                              ] -     self.rules.mkdir()
2022-12-24 09:43:27.511 [ERROR] [HABApp                              ] -   File "/usr/lib/python3.9/pathlib.py", line 1312, in mkdir
2022-12-24 09:43:27.511 [ERROR] [HABApp                              ] -     self._accessor.mkdir(self, mode)
2022-12-24 09:43:27.511 [ERROR] [HABApp                              ] - PermissionError: [Errno 13] Permission denied: 'rules'o

Once the directory is created, and after restarting habapp.service, habapp still is not able to access to the rest API with the same error as in the previous message.

I do not know if it may be relevant, but when I set “Allow basic authentication” the openhab log has some warning

2022-12-24 10:03:16.801 [WARN ] [.transport.servlet.ServletController] - Can't find the request for http://192.168.27.82:8080/rest/inbox's Observer
2022-12-24 10:03:16.805 [WARN ] [.transport.servlet.ServletController] - Can't find the request for http://192.168.27.82:8080/rest/things's Observer
2022-12-24 10:03:16.822 [WARN ] [.transport.servlet.ServletController] - Can't find the request for http://192.168.27.82:8080/rest/items's Observer
2022-12-24 10:03:16.825 [WARN ] [.transport.servlet.ServletController] - Can't find the request for http://192.168.27.82:8080/rest/ui/components/system:sitemap's Observer

What happens if you use http://USER:PASSWORD@192.168.27.82:8080/rest/systeminfo?

Could you also apply “fix permissions” from the openhabian-config menu and see if this will allow HABApp to create the rules folder? (restart of HABApp required)

What happens if you use http://USER:PASSWORD@192.168.27.82:8080/rest/systeminfo ?

I forgot to mention that I also tried this. It behaves exactly in the same way. I have tried with the raspberry user (openhabian) and with the openhab user (admin).

I then tried with the working system (which is on openhab 3.3.0M5) but I get exactly the same behavior, when trying to access to the rest API through the browser) even though habapp (which is still on 0.30.3 as I was unable to upgrade python) works well.

In order to avoid the browser and the network, I also tried with wget directly from the raspberry and it gives these errors

 wget http://user:pass@192.168.27.82:8080/rest/systeminfo
--2022-12-24 15:27:55--  http://openhabian:*password*@192.168.27.82:8080/rest/systeminfo
Connecting to 192.168.27.82:8080... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Unknown authentication scheme.

Username/Password Authentication Failed.

I also tried with localhost and with the address of the production system (on OH3.3.0M5) The error is always the same.

EDIT: I also made a test with curl. If I copy the expression that appears in the API explorer

curl -X 'GET' \
  'http://192.168.27.82:8080/rest/systeminfo' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer ** several lines of random characters** '

the query returns the info, but if I provide username and password, as suggested in the docs

 curl -X GET --header "Accept: application/json" "http://192.168.27.2:8080/rest/systeminfo" -u username:password

It returns

{"error":{"message":"Invalid credentials","http-code":401}}

EDIT2:
if username and password are the ones of openhab and not the ones for logging into the raspberry, the curl command returns the right informations. I made this test because inthe openhab log I saw

[WARN ] [ore.io.rest.auth.internal.AuthFilter] - Unauthorized API request from 192.168.27.82: User not found: openhabian

but this does not help with the http command

Maybe I should create an openhab user with the same credential of the raspberry login?

No - check you config.yaml and make sure it contains the correct credentials (the ones for openhab).
Then restart HABApp.
If the user/pw works with curl it has to work with HABApp.

1 Like

Many thanks, I overlooked the step of modifying config.yml, adding username and password.