'InfluxDBClientError: retention policy not found: autogen

I am going through https://www.influxdata.com/blog/getting-started-python-influxdb/ documentation to query influxdb with python.

I am able to create the database:

client = InfluxDBClient(host='localhost', port=8086)
client.create_database('pyexample')
client.get_list_database() 
client.switch_database('pyexample')

Plus I am also sending data inside the database:

json_body = [
{
    "measurement": "brushEvents",
    "tags": {
        "user": "Carol",
        "brushId": "6c89f539-71c6-490d-a28d-6c5d84c0ee2f"
    },
    "time": "2018-03-28T8:01:00Z",
    "fields": {
        "duration": 127
    }
},
{
    "measurement": "brushEvents",
    "tags": {
        "user": "Carol",
        "brushId": "6c89f539-71c6-490d-a28d-6c5d84c0ee2f"
    },
    "time": "2018-03-29T8:04:00Z",
    "fields": {
        "duration": 132
    }
},
{
    "measurement": "brushEvents",
    "tags": {
        "user": "Carol",
        "brushId": "6c89f539-71c6-490d-a28d-6c5d84c0ee2f"
    },
    "time": "2018-03-30T8:02:00Z",
    "fields": {
        "duration": 129
    }
}
]

Invoking the json body as:

client.write_points(json_body)
True 

But soon now, I want to query the metrics from the database with:

client.query('SELECT "duration" FROM "pyexample"."autogen"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')

This query results in a error:

File ipython-input-31-6e47204db16b, line 1, in module client.query('SELECT "duration" FROM "pyexample"."autogen"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')

File "/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py", line 420, in query in data.get('results', [])

File "/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/resultset.py", line 25, in init raise InfluxDBClientError(self.error)

InfluxDBClientError: retention policy not found: autogen

How can I get the query result ?

I checked the retention policy where also found error:

client.query('SHOW RETENTION POLICIES')

Traceback (most recent call last):

File "", line 1, in client.query('SHOW RETENTION POLICIES')

File "/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py", line 409, in query expected_response_code=expected_response_code

File "/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py", line 286, in request raise InfluxDBClientError(response.content, response.status_code)

InfluxDBClientError: 400: {"error":"error parsing query: found EOF, expected ON at line 1, char 25"}



Solution 1:[1]

Change autogen to default:

client.query('SELECT "duration" FROM "pyexample"."default"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')

Solution 2:[2]

It depends on what error message you're getting. In my case, I got error "retention policy not found: forever" which translates to - A retention policy named "forever" is not found.

And I fixed it by:

  • Enter InfluxDB docker container
  • Launch influx
  • use collectd to select database
  • Create a new retention policy named "forever": create retention policy "forever" on "collectd" duration 2d replication 1

The official documentation can be found: Manage retention policy

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stanko
Solution 2 Quinn