Python 写入influxdb不会返回错误,但不会存储任何数据

Python 写入influxdb不会返回错误,但不会存储任何数据,python,influxdb-python,Python,Influxdb Python,我正在尝试将一些传感器数据写入XDB。客户端没有返回错误,但没有数据到达数据库。你能帮我一下吗?我到处玩标签,不同的,时间格式等,但没有用。我读了我能找到的东西,但不知怎的我迷路了。 我使用的是XDB 1.8.3 def create_dictionary_for_value(temperature,humidity): return [{ "measurement": "kojiboxclimate",

我正在尝试将一些传感器数据写入XDB。客户端没有返回错误,但没有数据到达数据库。你能帮我一下吗?我到处玩标签,不同的,时间格式等,但没有用。我读了我能找到的东西,但不知怎的我迷路了。 我使用的是XDB 1.8.3

def create_dictionary_for_value(temperature,humidity):
    return [{
            "measurement": "kojiboxclimate",
            "tags": {
                "host": "server01",
                "region": "us-west"
            },
            "time": datetime.datetime.utcnow().isoformat(),
            "fields": {
                "temperature": temperature,
                "humidity": humidity
            }
    }]

def main():
    client = InfluxDBClient(HOST, PORT, USER, PASSWORD, DBNAME)
    retention_policy = 'my_policy'
    client.create_retention_policy(retention_policy, '3d', 3, default=True)

    while True:
        temperature, humidity = sensor.read()
        payload = create_dictionary_for_value(temperature, humidity)
        print("{}\n".format(payload))
        client.write_points(payload, retention_policy=retention_policy, protocol='json')
        result = client.query('select value from kojiboxclimate;')
        print("Result: {0}".format(result))
        time.sleep(60)
有效载荷的输出产生了我期望的结果:

[{'fields':{'temperature':20.164034485389493,“湿度”: 38.62821393148699},'标签':{'host':'server01','region':'uswest'},'时间':'2020-11-26T19:00:15.042571','measurement': “kojiboxclimate”}]


结果集是空的,数据库也是空的。

当我尝试使用您的代码时,它似乎对我有效,除了搜索查询

您尝试使用以下代码行查询数据:

result=client.query('select value from kojiboxclimate;')
这样,您可以尝试获取数据的字段
,但该字段不存在

如果要获取所有数据,可以执行以下操作:

result=client.query('select*fromKojiboxClimate;')
例如,如果您想获得温度,可以使用以下代码段:

result=client.query('从kojiboxclimate中选择温度;')

我似乎遇到了一个复合问题。我在脚本中进行了编辑。我同时重新安装了图书馆,我想这已经修复了它。但与此同时,我没有意识到我破坏了我的查询。非常感谢你的帮助。修复重新安装的库上的查询现在可以正常工作。