Trouble configuring InfluxDB access

I am running HA and InfluxDB in Docker on a Synology.
Both containers run without any problem but getting HA to write its sensor data into a bucket on InfluxDB does not work.

I am running:

Home Assistant 2023.1.7
InfluxDB v2.6.1

I startet of with a configuration like this

influxdb:
  host: 192.168.1.110
  port: !secret influx_port
  database: home_assistant
  username: !secret influx_username
  password: !secret influx_password

and got the error message:
InfluxDB database is not accessible due to ā€˜401: {ā€œcodeā€:ā€œunauthorizedā€,ā€œmessageā€:ā€œUnauthorizedā€}ā€™. Please check that the database, username and password are correct and that the specified user has the correct permissions set.

Trying to fix the issue I changed the configuration to the following, because of the version number of InfluxDB (2.6.1):

influxdb:
  host: 192.168.1.110
  api_version: 2
  port: 8086
  organization: !secret influx_organization
  token: !secret influx_token

Organization is the id found on InfluxDB, the same goes for the token, which is the token for the bucket I want to write to.

When checking the configuration in HA the config will not prevent HA from startingā€¦ however, now the logs show this error:

Logger: homeassistant.setup
Source: components/influxdb/__init__.py:365
First occurred: 11:19:19 (1 occurrences)
Last logged: 11:19:19

Error during setup of component influxdb
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 453, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 495, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "/usr/local/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/local/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/usr/local/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/rest.py", line 217, in request
    r = self.pool_manager.request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/request.py", line 78, in request
    return self.request_encode_body(
  File "/usr/local/lib/python3.10/site-packages/urllib3/request.py", line 170, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/usr/local/lib/python3.10/site-packages/urllib3/poolmanager.py", line 376, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 525, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.10/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 453, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/ssl_.py", line 495, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "/usr/local/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/local/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/usr/local/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
urllib3.exceptions.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 253, in _async_setup_component
    result = await task
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/influxdb/__init__.py", line 486, in setup
    influx = get_influx_connection(conf, test_write=True)
  File "/usr/src/homeassistant/homeassistant/components/influxdb/__init__.py", line 393, in get_influx_connection
    write_v2(b"")
  File "/usr/src/homeassistant/homeassistant/components/influxdb/__init__.py", line 365, in write_v2
    write_api.write(**data)
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/client/write_api.py", line 371, in write
    results = list(map(write_payload, payloads.items()))
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/client/write_api.py", line 369, in write_payload
    return self._post_write(_async_req, bucket, org, final_string, payload[0])
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/client/write_api.py", line 517, in _post_write
    return self._write_service.post_write(org=org, bucket=bucket, body=body, precision=precision,
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/service/write_service.py", line 62, in post_write
    (data) = self.post_write_with_http_info(org, bucket, body, **kwargs)  # noqa: E501
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/service/write_service.py", line 166, in post_write_with_http_info
    return self.api_client.call_api(
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/api_client.py", line 341, in call_api
    return self.__call_api(resource_path, method,
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/api_client.py", line 171, in __call_api
    response_data = self.request(
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/api_client.py", line 386, in request
    return self.rest_client.POST(url,
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/rest.py", line 304, in POST
    return self.request("POST", url,
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/rest.py", line 240, in request
    raise ApiException(status=0, reason=msg)
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/rest.py", line 360, in __init__
    super().__init__(response=http_resp)
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/client/exceptions.py", line 16, in __init__
    self.message = self._get_message(response)
  File "/usr/local/lib/python3.10/site-packages/influxdb_client/client/exceptions.py", line 22, in _get_message
    if response.data:
AttributeError: 'NoneType' object has no attribute 'data'

Any help here is appreciated! How can I get HA to access the InfluxDB bucket and write the sensor data into it?

Alright, for those interestedā€¦ I managed.

SInce I do not have any certificates (yet), the connection is running on HTTP, and version 2 of InfluxDB is by default pointing at HTTPS. Hence, I added a simple

ssl: false

to the configuration file.
Then I got an error message basically saying the bucket ā€œHome Assistantā€ was not found. No wonder, thatā€™s not the name of the bucketā€¦ So, in v2, you do not specify a database(name) in the configuration, but a bucket. Initially I was expecting the token to clarify that, but thatā€™s not the case, and I added the line

bucket: !secret influx_bucket

to my configuration and defined the name of the bucket in the secrets file.
Checked the configuration file, restarted HA, and Bob is your uncleā€¦

2 Likes