我正在通过https://www.influxdata.com/blog/getting-started-python-influxdb/文档来使用 python 查询 influxdb。
我能够创建数据库:
client = InfluxDBClient(host='localhost', port=8086)
client.create_database('pyexample')
client.get_list_database()
client.switch_database('pyexample')
另外,我还在数据库中发送数据:
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
}
}
]
调用 json 主体为:
client.write_points(json_body)
True
但很快,我想从数据库中查询指标:
client.query('SELECT "duration" FROM "pyexample"."autogen"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')
此查询导致错误:
文件 ipython-input-31-6e47204db16b,第 1 行,模块 client.query('SELECT "duration" FROM "pyexample"."autogen"."brushEvents" WHERE time > now() - 4d GROUP BY "user"')
文件“/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py”,第 420 行,在 data.get('results', []) 中的查询
文件“/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/resultset.py”,第 25 行,在init中 引发 InfluxDBClientError(self.error)
InfluxDBClientError: retention policy not found: autogen
我怎样才能得到查询结果?
我检查了保留政策,也发现了错误:
client.query('SHOW RETENTION POLICIES')
回溯(最近一次通话最后):
文件“”,第 1 行,在 client.query('SHOW RETENTION POLICIES')
文件“/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py”,第 409 行,查询 expected_response_code=expected_response_code
请求中的文件“/home/rahul/anaconda2/lib/python2.7/site-packages/influxdb/client.py”,第 286 行,引发 InfluxDBClientError(response.content,response.status_code)
InfluxDBClientError: 400: {"error":"error parsing query: found EOF, expected ON at line 1, char 25"}