0

我目前正在尝试使用 influxdb python 绑定将我收集的一些数据插入到 influxdb 中。

但是,当我尝试使用以下方法插入数据时:

def insert(self,datapoints):
        '''Takes a list of datapoints created via create_json_dict()
           Inserts these into the InfluxDB.'''
        try:
            print(type(datapoints))
            print(datapoints)
            if self.client.write_points(datapoints) == True:
                print("Inserted for process {0} syscall {1} with time {2}".format(datapoints['processname'],datapoints['systemcall'],datapoints['time']))            
            else:
                print("Something went wrong")
        except Exception as e:
            print("{0} occured in insert ".format(str(e)))

口译员抛出

<class 'list'>
[{'measurement': 'traces', 'tags': {'processname': ''}, 'time': '2019-06-26T12:10:43+02:00', 'fields': {'systemcall': 'timerfd_settime'}}]
list indices must be integers or slices, not str occured in insert 

我究竟做错了什么?JSON 在我看来格式正确。

提前致谢。

4

1 回答 1

1

当您使用此函数时,type(datapoints)<class 'list'>,但稍后.format您尝试datapoints使用字符串(例如datapoints['processname'])引用 。我认为您期望数据点对象的类型是dict

于 2019-06-26T10:22:21.170 回答