A solution to the Influx DB CLI error “Failed to check token: received status code 401 from server” including instructions to install the InfluxDB V2 CLI.
As I worked my way through using the Influx Database I tried using the InfluxDB CLI. However, no matter what I seemed to do I got this error, which was super annoying.
linux$ linux$ influx Failed to check token: received status code 401 from server linux$ influx create Failed to check token: received status code 401 from server linux$ influx adsf Failed to check token: received status code 401 from server linux$ influx setup Failed to check token: received status code 401 from server
I tried googling around to try to figure out what was happening but really didn’t see anything that would explain that behavior. However, I did find one comment that if you were using Docker you could run the CLI by running in the shell. So I tried that:
linux$ docker exec -it 89ffd4bb9ec5 /bin/bash root@89ffd4bb9ec5:/# influx version Influx CLI 2.0.4 (git: 4e7a59bb9a) build_date: 2021-02-08T17:47:02Z
When I originally installed the client (on Ubuntu) I did this:
linux$ sudo apt install influxdb-client [sudo] password for arh: Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: linux-hwe-5.4-headers-5.4.0-71 Use 'sudo apt autoremove' to remove it. The following NEW packages will be installed: influxdb-client 0 upgraded, 1 newly installed, 0 to remove and 97 not upgraded. Need to get 1,146 kB of archives. After this operation, 3,969 kB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 influxdb-client amd64 1.1.1+dfsg1-4 [1,146 kB] Fetched 1,146 kB in 1s (1,883 kB/s) Selecting previously unselected package influxdb-client. (Reading database ... 275845 files and directories currently installed.) Preparing to unpack .../influxdb-client_1.1.1+dfsg1-4_amd64.deb ... Unpacking influxdb-client (1.1.1+dfsg1-4) ... Setting up influxdb-client (1.1.1+dfsg1-4) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
When I ran the version look what I got:
linux$ /usr/bin/influx -version InfluxDB shell version: 1.1.1
Now we know the problem. I have the wrong version of the CLI. This was caused by two things
- I installed the docker version of InfluxDB. So I never had the command line version on my linux box.
- The influxdb-client that you get from whatever the debian source on Ubuntu is the 1.xx version. It is too bad that you can’t “sudo apt install influxdbv2-client” Oh well.
To fix this start by nuking the old version.
linux$ sudo apt-get remove influxdb-client Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: linux-hwe-5.4-headers-5.4.0-71 Use 'sudo apt autoremove' to remove it. The following packages will be REMOVED: influxdb-client 0 upgraded, 0 newly installed, 1 to remove and 97 not upgraded. After this operation, 3,969 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 275851 files and directories currently installed.) Removing influxdb-client (1.1.1+dfsg1-4) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Then download the “InfluxDB Cloud CLI” (which is just a standalone version of the CLI. You can get it from the influxdata.com website here.
Scroll down to the InfluxDB Cloud CLI
Then follow the instructions (Notice that I moved it to /usr/local/bin)
linux$ wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.0.6-linux-amd64.tar.gz --2021-05-21 11:08:48-- https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.0.6-linux-amd64.tar.gz Resolving dl.influxdata.com (dl.influxdata.com)... 126.96.36.199, 188.8.131.52, 184.108.40.206, ... Connecting to dl.influxdata.com (dl.influxdata.com)|220.127.116.11|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 11758006 (11M) [application/x-gzip] Saving to: ‘influxdb2-client-2.0.6-linux-amd64.tar.gz’ influxdb2-client-2.0.6-linux-amd64.tar.gz 100%[===========================================================================================================================>] 11.21M 10.8MB/s in 1.0s 2021-05-21 11:08:50 (10.8 MB/s) - ‘influxdb2-client-2.0.6-linux-amd64.tar.gz’ saved [11758006/11758006] linux$ tar xvf influxdb2-client-2.0.6-linux-amd64.tar.gz influxdb2-client-2.0.6-linux-amd64/LICENSE influxdb2-client-2.0.6-linux-amd64/README.md influxdb2-client-2.0.6-linux-amd64/influx linux$ sudo mv influxdb2-client-2.0.6-linux-amd64/influx /usr/local/bin
Now when you check the version, you are in the money
linux$ influx version Influx CLI 2.0.6 (git: 4db98b4c9a) build_date: 2021-04-29T16:48:12Z