【问题标题】:Unable to add data to InfluxDB using dict type as field entry无法使用 dict 类型作为字段条目将数据添加到 InfluxDB
【发布时间】:2021-10-25 16:50:07
【问题描述】:

我无法发现使用以下方案向我的 InfluxDB 添加数据的错误:

from influxdb_client import InfluxDBClient
import datetime
from influxdb_client.client.write_api import ASYNCHRONOUS

client_db = InfluxDBClient(url=f"http://{ip}:{port_db}", token=token, org=org)
write_api = client_db.write_api(write_options=ASYNCHRONOUS)

data = {
          "measurement": "title",
          "time": datetime.datetime.now().strftime("%m/%d/%y %H:%M:%S.%f"),
          "fields": db_dict    
       }    
      
write_api.write(bucket=bucket, org=org, record=data)

其中 db_dict 是具有多个 key:value 条目的字典。我没有收到任何错误,但我的数据库仍然没有条目。在遵循这种模式之前效果很好 - 这次不是。我也尝试了改变时间偏移,但没有解决问题。有什么想法吗?感谢每一个提示。

【问题讨论】:

    标签: python grafana influxdb


    【解决方案1】:

    尝试将 time 字段保留为 python 日期时间或将其转换为 Unix 时间戳(以纳秒为单位),而不是将其格式化为字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2021-06-19
      • 2021-04-26
      • 1970-01-01
      相关资源
      最近更新 更多