Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 (Unauthorized) HttpRequestException #73

Open
jnewcomb opened this issue Nov 30, 2020 · 0 comments
Open

401 (Unauthorized) HttpRequestException #73

jnewcomb opened this issue Nov 30, 2020 · 0 comments

Comments

@jnewcomb
Copy link

jnewcomb commented Nov 30, 2020

I'm getting this exception when running the example.
Response status code does not indicate success: 401 (Unauthorized)

It's probably because the following URL:
http://localhost:8086/query?q=show%20databases
Returns:
{"code":"unauthorized","message":"unauthorized access"}

Even just calling this code gives me the same exception:

var client = new InfluxClient(new Uri("http://localhost:8086"), "administrator", "administrator");
await client.ShowDatabasesAsync();

I guess it is because I need to include the token as part of the client request - but I can't work out how to do this from the client? Where do I specify a token for my administrator user?

I have posted more details on my InfluxDB2 setup here:
https://community.influxdata.com/t/getting-started-with-influxdb-and-docker/16989

Update
The help states that: "InfluxDB 2.0 requires authentication and does not support the InfluxDB 1.x auth-enabled = false configuration option.

I have tried adding the token for the administrator to:
/root/.influxdbv2/config
But it still keeps returning with the 401 error..

# ls -l
total 124
-rw------- 1 root root    513 Dec  1 16:14 configs
drwxr-xr-x 4 root root   4096 Dec  1 15:57 engine
-rw------- 1 root root 131072 Dec  1 16:15 influxd.bolt
# pwd
/root/.influxdbv2
# cat configs
[administrator]
  url = "http://localhost:8086"
  token = "ZjUBmuoMC-Y-MQqESsS8XqxTyVryoNg1-xQQsuY-Alw2S-zH4DE6hXpkSu-J6DTW9mM7cJf7wG308KoZ2Dp2HQ=="
  org = "AdvancedEnergy"
  active = true

Any hints/tips on if this can be fixed on the client-side appreciated - and apologies for the noob question!
Isn't this a stumbling block for anyone using InfluxDB2?

For the record..
This is how I've setup InfluxDB from the command line..
Pull influxdb2 to the local filesystem and create a new docker container from it (Run from cmd.exe)

docker pull quay.io/influxdb/influxdb:v2.0.2
docker run --name influxdb -p 8086:8086 quay.io/influxdb/influxdb:v2.0.2

Then in the docker container CLI:
Setup the users, bucket and org names. (See 'influx setup -h')

influx setup --skip-verify --bucket sandbox --org MyOrgName --username administrator --password administrator --retention 0 --token UseThisToken_UseThisToken_UseThisToken_UseThisToken_UseThisToken_UseThisToken_UseThisT==

Then we need to add the token to /root/.influxdbv2/config file - otherwise we need provide it for every request.. (See 'influx config create -h')

influx config create --active --org MyOrgName --config-name administrator --host-url http://localhost:8086 --token UseThisToken_UseThisToken_UseThisToken_UseThisToken_UseThisToken_UseThisToken_UseThisT==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant