【问题标题】:Influx DB Python 'list indices must be integers not str'Influxdb Python'列表索引必须是整数而不是str'
【发布时间】:2019-06-26 10:15:32
【问题描述】:

我目前正在尝试使用 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 在我看来格式正确。

提前致谢。

【问题讨论】:

    标签: python influxdb influxdb-python


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-09
      • 1970-01-01
      • 1970-01-01
      • 2017-01-27
      • 2016-02-09
      • 2015-05-03
      • 2020-09-06
      相关资源
      最近更新 更多