2

When try to write the data into influxDB using influxDB client. i am getting the below error. I was able to login to the influxDB web browser using http://localhost:8086 with the same credentials provided in the code. But facing with the unauthorized message when using python code. any help would be appreciated.

Error: raise InfluxDBClientError(err_msg, response.status_code) influxdb.exceptions.InfluxDBClientError: 401: {"code":"unauthorized","message":"Unauthorized"}

Code:

from influxdb import InfluxDBClient
from datetime import datetime


    client = InfluxDBClient('localhost', 8086, 'username', 'password', 'bucket_name') 
    for row in df.iterrows():
        influxJson = [
                    {
                        "measurement":"testing123",
                        "time" : datetime.utcnow().isoformat() + "Z",
                        "tags": {
                            'ResiliencyTier':'targetResiliencyTier',
                            'lob' : 'abcdefgh'
                        },
                        "fields": {
                            columns[0][0] : str(row[1][0]),
                            columns[1][0] : str(row[1][1]),

                        }
                    }
                ]
        client.write_points(influxJson) 
    print("InfluxDB injection DONE")

startProcess()

Thanks

learning fun
  • 97
  • 1
  • 1
  • 5
  • 4
    looks like you are using the https://github.com/influxdata/influxdb-python client which only works with influxDB 1.x. You tagged your question for influxdb-2. You need to use this client https://github.com/influxdata/influxdb-client-python for 2.x. – Phil Jan 19 '22 at 23:58

1 Answers1

1

Error code 401 (unauthorized) can be avoided in dev env by enabling http access in influx config file:

[http]
  # Determines whether HTTP endpoint is enabled.
  enabled = true

genarally config file can be found at:

/etc/influxdb/influxdb.conf

KIRAN KUMAR B
  • 404
  • 4
  • 8