Python does not write data into influxdb

1.8k views Asked by At

I am trying to insert some test data into InfluxDB using python, but data is not inserted when query data.

Do you have some idea what could be the issue?

I am using code from the documentation:

from influxdb import InfluxDBClient


def main(host='localhost', port=8086):
    user = 'root'
    password = 'root'
    dbname = 'example'

    query = 'select value from cpu_load_short;'
    json_body = [
        {
            "measurement": "cpu_load_short",
            "tags": {
                "host": "server01",
                "region": "us-west"
            },
            "time": "2009-11-10T23:00:00Z",
            "fields": {
                "value": 0.64
            }
        }
    ]

    client = InfluxDBClient(host, port, user, password, dbname)

    #client = InfluxDBClient(host, port)

    print("Create database: " + dbname)
    client.create_database(dbname)

    print("Create a retention policy")
    client.create_retention_policy('awesome_policy', '3d', 3, default=True)


    print("Write points: {0}".format(json_body))
    client.write_points(json_body)

    print("Querying data: " + query)
    result = client.query(query)

    print("Result: {0}".format(result))




if __name__ == '__main__':

    main()    

When I check from CLI the database is created successfully but it is empty, this is the output of the code:

Result: 'ResultSet({})'

Thanks!

0

There are 0 answers