英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论