首页 文章

Python Influxdb timestamp valueerror

提问于
浏览
0

我试图使用write_points()将数据添加到python中的Influxdb数据库 . 但是,我收到write_points的时间戳部分的错误 . 我曾尝试多种方式定义时间戳,首先使用

info = line.split()
s_time = info[2]
i_time = "20" + s_time[6:8] + "-" + s_time[0:2] + "-" + s_time[3:5] + ' ' + s_time[9:]
fixedtime = datetime.datetime.strptime(i_time, "%Y-%m-%d %H:%M:%S")

并将时间添加到JSON以及Influxdb所需的所有其他部分我也尝试将时间戳设为int

inttime = int(time.time()*1000);

这给了我一个纪元时间 . 这两个时间戳都会在我的代码中从此行引发值错误

dbclient.write_points(db_point, time_precision='ms', protocol='json')

并在最后一行

if isinstance(timestamp, Integral):
        return timestamp  # assume precision is correct if timestamp is int
    if isinstance(_get_unicode(timestamp), text_type):
        timestamp = parse(timestamp)
    if isinstance(timestamp, datetime):
        if not timestamp.tzinfo:
            timestamp = UTC.localize(timestamp)
        ns = (timestamp - EPOCH).total_seconds() * 1e9
        if precision is None or precision == 'n':
            return ns
        elif precision == 'u':
            return ns / 1e3
        elif precision == 'ms':
            return ns / 1e6
        elif precision == 's':
            return ns / 1e9
        elif precision == 'm':
            return ns / 1e9 / 60
        elif precision == 'h':
            return ns / 1e9 / 3600
    raise ValueError(timestamp)

在line_protocol.py中

当我使用纪元时间时,整数以某种方式被转换为一个集合,因此它不会传递任何if语句,但我不知道为什么字符串确实传递了一个if语句

1 回答

相关问题