1

我有一个字典列表如下:

[{"vins": "50EA1LGA5KA900001", "use": "abc", "owner": "Jack"}, {"vins": "50EA1LGA0KA900004", "use": "xyz", "owner": "Laura"}, {"vins": "50EA1LGA2KA900005", "use": "pqr", "owner": "Sam"}]

我想通过创建一个名为“vin_info”的新流入测量来编写上述字典,如下所示:我期望的输出是:

vins | use | owner
50EA1LGA5KA900001 | abc | Jack
50EA1LGA0KA900004 | xyz | Laura
50EA1LGA2KA900005 | pqr | Sam

到目前为止,我尝试写入数据的代码是:

 data =   [{"vins": "50EA1LGA5KA900001", "use": "abc", "owner": "Jack"}, {"vins": "50EA1LGA0KA900004", "use": "xyz", "owner": "Laura"}, {"vins": "50EA1LGA2KA900005", "use": "pqr", "owner": "Sam"}]
 db = 'abc'
 query = 'select * from vin_info'
    client = InfluxDBClient(host='*****', port=8086,database=db)
        print("Connection Established")
        client.write_points(data)
        result = client.query(query)
        print(result)

但得到以下错误:

AttributeError: 'str' object has no attribute 'get'

我不确定如何将上述数据插入到流入测量中。有人可以在这里帮助我吗?

提前致谢!

4

1 回答 1

0
query = 'select * from vin_info'

您正在调用 measure vin_info,它不会出现在数据中。

尝试这个:

influx_data = []

for x in data:
    new_json = {}
    new_json.update("measurement", "vin_info")
    new_json.update("tags",x)

influx_data.append(new_json)

当您选择测量时,您应该会看到所有标签。

此外,根据influxDBClient doc,查询返回一个表。

所以也试试这个:

tables = query_api.query(query)

for table in tables:
    print(table)
于 2020-12-12T12:30:44.683 回答