Reputation: 33608
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?
Upvotes: 0
Views: 4741
Reputation: 31
You could use username and password instead of token.
import influxdb_client
from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS
_influxdb_client = InfluxDBClient(
url=f"http://localhost:8086",
username=os.environ['INFLUXDB_USERNAME]',
password='os.environ['INFLUXDB_PASSWORD']',
verify_ssl=False)
I'm using influxDB v2.0.9 and client influxdb_client library v1.36.1
If you are using influxdb v1.8.x with influxdb_client library then you should pass username and password in the token field for authorization.
import influxdb_client
from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS
_influxdb_client = InfluxDBClient(
url=f"http://localhost:8086",
token=f"os.environ['INFLUXDB_USERNAME]:os.environ['INFLUXDB_PASSWORD']",
verify_ssl=False)
Upvotes: 1
Reputation: 1
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)
Upvotes: 0
Reputation: 577
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.
Upvotes: 2