【问题标题】:InfluxDB Unauthorized 401 - with localhost accessInfluxDB Unauthorized 401 - 具有本地主机访问权限
【发布时间】:2023-02-03 05:09:52
【问题描述】:

当尝试使用 influxDB 客户端将数据写入 influxDB 时。我收到以下错误。我能够使用http://localhost:8086 和代码中提供的相同凭据登录到 influxDB Web 浏览器。但是在使用 python 代码时面临未经授权的消息。任何帮助,将不胜感激。

错误: 提高 InfluxDBClientError (err_msg, response.status_code) influxdb.exceptions.InfluxDBClientError: 401: {"code":"unauthorized","message":"Unauthorized"}

代码:

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()

谢谢

【问题讨论】:

标签: python influxdb influxdb-python influxdb-2


【解决方案1】:

通过在 influx 配置文件中启用 http 访问,可以在开发环境中避免错误代码 401(未经授权):

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

一般配置文件可以在以下位置找到:

/etc/influxdb/influxdb.conf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 2020-11-11
    • 2012-05-23
    • 2010-10-27
    • 1970-01-01
    相关资源
    最近更新 更多