Influxdb2 authentication failing

Hi all,
i’m using mycodo for two years now mainly for measuring and alert mails and it’s great.

I setup the latest version on a new rpi4 with 64Bit RaspianOS.
I created one input “openweather city” and it is collecting values fine.
I set up the mosquitto mqtt server and created an action to write temperature from input to mqtt.
On the existing rpi the collection of these values worked sucessfully.

So far so good.
However, i noticed that the values from the input were not written to the influxdb, with an error:
2023-07-27 10:52:26,576 - DEBUG - mycodo.influx - Write point fail: (401)

Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.6.1', 'X-Platform-Error-Code': 'unauthorized', 'Date': 'Thu, 27 Jul 2023 09:52:26 GMT', 'Content-Length': '62'})
HTTP response body: {
	"code": "unauthorized",
	"message": "unauthorized access"
}

I followed kyles wiki and moved the mycodo.db to another filename and created a new db with new mycodo user.
Right after recreating the input everything was working, until:

2023-07-27 10:51:16,565 - DEBUG - mycodo.influx - Write point success: b'C,channel=0,device_id=4a8b73b6-80b2-490e-841c-e92f1d14ed31,measure=temperature value=16.43\npercent,channel=1,device_id=4a8b73b6-80b2-490e-841c-e92f1d14ed31,measure=humidity value=94\nPa,channel=2,device_id=4a8b73b6-80b2-490e-841c-e92f1d14ed31,measure=pressure value=1005\nC,channel=3,device_id=4a8b73b6-80b2-490e-841c-e92f1d14ed31,measure=dewpoint value=15.460587966760425\nm_s,channel=4,device_id=4a8b73b6-80b2-490e-841c-e92f1d14ed31,measure=speed value=5.14\nbearing,channel=5,device_id=4a8b73b6-80b2-490e-841c-e92f1d14ed31,measure=direction value=190'
2023-07-27 10:51:26,568 - DEBUG - mycodo.influx - Write point success: b'C,channel=0,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=43.816\nC,channel=1,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=43.3'
2023-07-27 10:51:41,502 - DEBUG - mycodo.influx - Write point success: b'C,channel=0,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=43.816\nC,channel=1,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=44.3'
2023-07-27 10:51:56,495 - DEBUG - mycodo.influx - Write point success: b'C,channel=0,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=43.816\nC,channel=1,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=44.3'
2023-07-27 10:52:11,852 - DEBUG - mycodo.influx - Write point success: b'C,channel=0,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=42.842\nC,channel=1,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=42.8'
2023-07-27 10:52:20,778 - DEBUG - mycodo - Refreshing misc settings
2023-07-27 10:52:26,576 - DEBUG - mycodo.influx - Write point fail: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.6.1', 'X-Platform-Error-Code': 'unauthorized', 'Date': 'Thu, 27 Jul 2023 09:52:26 GMT', 'Content-Length': '62'})
HTTP response body: {
	"code": "unauthorized",
	"message": "unauthorized access"
}
: b'C,channel=0,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=42.355\nC,channel=1,device_id=b3dbe3c5-7943-4345-beb3-4adec048a328,measure=temperature value=42.8'

Seems like it lost access to influxdb after “DEBUG - mycodo - Refreshing misc settings”

Anyone an idea, what that might be? Is “misc settings” the general settings page?

1 Like

This occurs when the configuration is saved and doesn’t affect influxdb.

There’s nothing to indicate what the issue is and unless you can reliably reproduce the issue, there’s little that I can do to understand the issue.

You can try upgrading influxdb by editing this line:

to:

INFLUXDB2_VERSION="2.7.1"

Then run:

sudo ~/Mycodo/mycodo/scripts/upgrade_commands.sh update-influxdb-2

Thanks. I was thinking maybe an old browser stored password on the general configuration page could be the culprit, but the error persisted.

In the end i changed the installation to influxdb 1. There this issue was not happening.
(The short version to reproduce is: Setup Raspberry OS latest 64-Bit, mycodo 8.15.8, Create Input openweather, activate it, wait, errors occur)
But I will try to create a detailed reproduction of the issue later on a new SD Card, because the card had some write issues…
If it occurs again i will check the update to influxdb 2.7.1.

If the influxdb settings were changed on the configuration page, this could be the cause of the issue. What were the settings before and after saving the page? (perform a refresh to be absolutely sure what values are shown are what’s from the database)

I deactivated sending of anonymous usage data. Then saved.

Before there was a longer password for the db set.
I used a longer password for the db when the issue happenend the first time.
Thinking it could be to long i shortened it the second time.
However i entered the correct password afterwards and the issue persisted.

Now i did a complete clean re-install on a fresh sd card.
Steps to reproduce:

  1. put 2023-05-03-raspios-bullseye-arm64-lite.img.xz on a 64GB SD Card
  2. Install mycodo with the shell script with influxdb-2
  3. Create input “Openweather City” with all measurements, 180s interval and debug logging
  4. Create Chart highchart with all measurements on default dashboard
  5. Chart will be regulary updated (i waited maybe 1h, and saved settings in between)
  6. After that i added an output gpio
  7. After that i added an DHT22 input with all measurements and debug logging
  8. Create Chart highchart with all measurements off DHT22 on default dashboard
    Then i noticed, that Openweather Chart wasn’t showing any values.
    I checked the log file, but all seemed fine.
  9. Change on general settings - enable daemon debug logging
  10. restarted backend
  11. After that in the log file the errors from initial post coming up again. For both inputs.

I tried the upgrade to 2.7.1

#### Ensuring compatible version of influxdb 2.x is installed ####
#### Incorrect InfluxDB version (v) installed. Should be v2.7.1-1
#### Stopping influxdb 1.x (if installed)...
#### Uninstalling influxdb 1.x (if installed)...
Paketlisten werden gelesen… Fertig
Abhängigkeitsbaum wird aufgebaut… Fertig
Statusinformationen werden eingelesen… Fertig
Paket »influxdb« ist nicht installiert, wird also auch nicht entfernt.
0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.
#### Installing InfluxDB v2.7.1-1...
(Lese Datenbank ... 40520 Dateien und Verzeichnisse sind derzeit installiert.)
Vorbereitung zum Entpacken von influxdb2-2.7.1-arm64.deb ...
Entpacken von influxdb2 (2.7.1-1) über (2.6.1-1) ...
influxdb2 (2.7.1-1) wird eingerichtet ...
Config file /etc/influxdb/config.toml already exists, writing defaults to /etc/influxdb/config.toml.defaults
Vormals nicht ausgewähltes Paket influxdb2-client wird gewählt.
(Lese Datenbank ... 40520 Dateien und Verzeichnisse sind derzeit installiert.)
Vorbereitung zum Entpacken von influxdb2-client-2.7.1-arm64.deb ...
Entpacken von influxdb2-client (2.7.1-1) ...
dpkg: Fehler beim Bearbeiten des Archivs influxdb2-client-2.7.1-arm64.deb (--install):
 Versuch, »/usr/bin/influx« zu überschreiben, welches auch in Paket influxdb2-cli 2.6.1 ist
dpkg-deb: Fehler: »einfügen«-Unterprozess wurde durch Signal (Datenübergabe unterbrochen (broken pipe)) getötet
Fehler traten auf beim Bearbeiten von:
 influxdb2-client-2.7.1-arm64.deb

it tried to additionally install influxdb2-client and failed with (translated): couldn’t overwrite /usr/bin/influx, which is also in package influxdb2-cli 2.6.1

However:

$ influxd version
InfluxDB v2.7.1 (git: 407fa622e9) build_date: 2023-04-28T13:24:42Z

So i did a:

$ service influxdb restart

And the issue was still occuring. I tried a reboot with same result.

I can attach the complete daemon log if this is of any help?

What you did was change the password Mycodo uses to authenticate with influxdb, thereby changing the correct password to an incorrect password. This is why you then had authentication issues.

What’s important and what I asked previously is: what were the influxdb settings before saving anything on the configuration page, and what are the influxdb settings after saving the configuration page (and a page refresh to display the actual settings)?

Sorry Kyle, i didn’t get that.
In this re-install I didn’t change the database settings at all.

There should not be any value in the influxdb password field. The field is only to be populated if the password is to be changed. Entering a value there will change the password from the default/correct password.

Why are the two fields highlighted? Is your browser populating those fields automatically from a previously saved user/password from somewhere else? If so, you need to disable that behavior.

1 Like

Ok, thanks. That would be it. Autofill. My firefox browser had it somehow stored for that page and filled it in automatically.
Now i cleared the password and removed all stored passwords for the mycodo page from my browser.
So user/password fields are not yellow any more. Password field is empty.

[edit: I created a new database.
And made sure, that FF doesn’t store the password.
Thanks again, @KyleGabriel
]

1 Like

You’re welcome. I’ll make a github issue to remind me to change the IDs of the fields so they aren’t the same as the login fields. That way browsers won’t even attempt to associate them for autofilling.

1 Like

Great, that will be a good permanent solution!