OpenHab3 with influxdb 2.1 persistence: "unauthorized access"

Setting up a brand new machine with the latest of everything.

  • Platform information:
    • OS: debian 11
    • Java Runtime Environment: OpenJDK Runtime Environment Zulu11.54+25-CA
    • openHAB version: 3.2.0
    • influxdb v2.1

Persistence is failing to connect to Influxdb

influxdb configuration is (I have trimmed the token):

# influx org list | grep shade
d2e8dc0d3b22984d	shade
# influx bucket list | grep enviro
ba66688e63b1cec8	enviro		infinite	168h0m0s		d2e8dc0d3b22984d	implicit
influx auth list | grep openhab3
ID			Description	Token User Name	User ID	Permissions
08f8562e2093c000	openhab3	00...==	admin		08f74450b593c000	[read:orgs/d2e8dc0d3b22984d/buckets/ba66688e63b1cec8 write:orgs/d2e8dc0d3b22984d/buckets/ba66688e63b1cec8]

openhab3 user should be able to connect to enviro bucket, org shade, using the “00…==” read/write token

Following the instructions for Influxdb V2 at InfluxDB (0.9 and newer) - Persistence Services | openHAB, I configured the influxdb service

#cat /etc/openhab/services/influxdb.cfg 

url=http://192.168.0.120:8086
token="00...=="
version=V2
# name of Organisation in InfluxDB V2
db=shade
# name of Bucket in InfluxDB V2
retentionPolicy=enviro

Restart openhab3, configure persistence for some items, and the openhab.log shows:

2022-02-25 12:25:37.240 [ERROR] [.client.write.events.WriteErrorEvent] - The error occurred during writing of data
com.influxdb.exceptions.UnauthorizedException: unauthorized access
	at com.influxdb.internal.AbstractRestClient.responseToError(AbstractRestClient.java:98) ~[bundleFile:?]
	at com.influxdb.client.internal.AbstractWriteClient.toInfluxException(AbstractWriteClient.java:574) ~[bundleFile:?]
	at com.influxdb.client.internal.AbstractWriteClient.lambda$new$12(AbstractWriteClient.java:181) ~[bundleFile:?]
...

I tried using the admin token with all permissions, with same error resulting.

Using

bucket = "enviro"
client = InfluxDBClient(url="http://localhost:8086", token="00...==", org="shade")

in a test python script connected to influxdb and wrote successfully.

Hey @morrowwm did you find a solution, I have the same problem with openhab 3.3.0 and influx db 2.4

@ComJack85 I’ve recently upgraded and found that I could not use either a bucket or user that had a digit in the name, such as ‘openhab3’, as soon as I changed back to ‘openhab’ for bucket and username it started working. Confirmed broken if I add back in the digit in bucket by rename, and in config UI, it does not work.

@lordmorgul This is not the case for me, the bucket and name do not contain a digit. :melting_face:

@lordmorgul But it gave me an idea. Under Settings - InfluxDB Persistence Service, I entered the token and left the password field empty. Now it works.

2 Likes

I had a very similar problem with OH 3.4.0 and InfluxDB 2.6.1.

For me, the solution was to remove the double-quotes from the token definition in /etc/openhab/services/influxdb.cfg

So, instead of:
token="00...=="

write just this:
token=00...==

Hope that helps someone else.