Search code examples
pythoninfluxdbinfluxdb-python

Influx DB Python 'list indices must be integers not str'


I'm currently trying to use the influxdb python bindings to insert some data I've collected into a influxdb.

However, when I try to insert the data using:

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

the interpreter throws

<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 

What am I doing wrong? The JSON looks well formed to me.

Thanks in advance.


Solution

  • When you used this function, the type(datapoints) was <class 'list'>, but then later in the .format you try to reference the datapoints with a string (e.g. datapoints['processname']). I think you're expecting the type of the datapoints object to be a dict