0

I'm new to InfluxDB and encountering an "unauthorized access" issue when trying to connect to my InfluxDB instance using the Python influxdb library. I'm receiving the following error message: Reason: Unauthorized HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'X-Influxdb-Build': 'OSS', 'X-Influxdb-Version': 'v2.7.0', 'X-Platform-Error-Code': 'unauthorized', 'Date': 'Wed, 17 May 2023 15:03:50 GMT', 'Content-Length': '55'}) HTTP response body: {"code":"unauthorized","message":"unauthorized access"}

Code Snippet that I tried from the InfluxDB documentation to connect using the python client library, was trying this to get familiar with the process :

 import influxdb_client, os, time
 from influxdb_client import InfluxDBClient, Point, WritePrecision
 from influxdb_client.client.write_api import SYNCHRONOUS

 token = os.environ.get("INFLUXDB_TOKEN")
 org = "Org_Name"
 url = "http://localhost:8086"

 write_client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)

 bucket="SensorDB"

 write_api = write_client.write_api(write_options=SYNCHRONOUS)
   
 for value in range(5):
   point = (
     Point("measurement1")
     .tag("tagname1", "tagvalue1")
     .field("field1", value)
   )
   write_api.write(bucket=bucket, org="Org_Name", record=point)
   time.sleep(1) # separate points by 1 second

What could be the cause of this error, and how can I resolve it?

Any guidance or suggestions would be greatly appreciated. Thank you!your text

1 Answers1

1

Assuming the token is set up correctly your InfluxDB instance, the problem is probably something to do with how the INFLUXDB_TOKEN environment variable is being set (or it's value.) To troubleshoot, you might try temporarily printing out the value of token and making sure it's the correct token.