How connect to locallhost influxdb from python and without token?

Question:

I am trying just simple connect to influxdb which started on localhost.

When I try just client:

influx --host 192.168.0.2 --port 8086

It works.

But when I try python:

import os
import json
from influxdb_client import InfluxDBClient, Point, WritePrecision

influxdb_url = os.environ['INFLUXDB_URL']
influxdb_host = os.environ['INFLUXDB_HOST']
influxdb_port = os.environ['INFLUXDB_PORT']

client = InfluxDBClient(url=influxdb_url)

I got exception

TypeError: __init__() missing 1 required positional argument: 'token'

But cli client can not connect without any tokens? Why do I need it in python? What token to use?

Asked By: Cherry

||

Answers:

InfluxDB 2.0 requires an authentication token for all API access. The client library is using the same APIs as anything else, so it needs a token to securely connect to InfluxDB.

You can create an auth token from the CLI or the GUI itself.

Answered By: mhall119

According to
https://influxdb-client.readthedocs.io/en/stable/api.html you can also auth. with username+pw on InfluxDB 2.x (works for me on 2.2.0).

e.g.:
client = InfluxDBClient(url=url,username='',password='',ssl=True, verify_ssl=True, org=org)

Answered By: gCW
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.