InfluxDB – 未经授权访问问题

huangapple go评论58阅读模式
英文:

InfluxDB - Unauthorized Access Issue

问题

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!

英文:

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

得分: 1

假设令牌已正确设置在您的InfluxDB实例中,问题可能与INFLUXDB_TOKEN环境变量的设置方式(或其值)有关。要进行故障排除,您可以尝试临时打印出token的值,并确保它是正确的令牌。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月18日 13:46:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76278056.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定