InfluxDB - Unauthorized Access Issue

'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!

Hey @ShounakBasu I’m facing exactly this problem. Were you able to find a solution? Thanks in advance for the help!

Oh nevermind, I just had to refresh my terminals environment variables!