Reputation: 435
I have this code to query a influx DB, but it is not working at all. Here is the python code.
import os
from influxdb import InfluxDBClient
username = u'{}'.format(os.environ['INFLUXDB_USERNAME'])
password = u'{}'.format(os.environ['INFLUXDB_PASSWORD'])
client = InfluxDBClient(host='127.0.0.1', port=8086, database='data',
username=username, password=password)
result = client.query("SELECT P_askbid_midprice1 FROM 'DCIX_OB' WHERE time > '2018-01-01';")
I got the following error, but it's still unclear how to fix the code above. If I query directly from influxdb with bash with SELECT P_askbid_midprice1 FROM 'DCIX_OB' WHERE time > '2018-01-01';
it worked perfectly fine.
Press ENTER or type command to continue
Traceback (most recent call last):
File "graph_influxdb.py", line 11, in <module>
result = client.query("SELECT P_askbid_midprice1 FROM 'DCIX_OB' WHERE time > '2018-01-01';")
File "/home/ubuntu/.local/lib/python3.5/site-packages/influxdb/client.py", line 394, in query
expected_response_code=expected_response_code
File "/home/ubuntu/.local/lib/python3.5/site-packages/influxdb/client.py", line 271, in request
raise InfluxDBClientError(response.content, response.status_code)
influxdb.exceptions.InfluxDBClientError: 400: {"error":"error parsing query: found DCIX_OB, expected identifier at line 1, char 31"}
How can I fix it?
Upvotes: 0
Views: 1909
Reputation: 529
you might be able to use Pinform which is some kind of ORM/OSTM (Object time series mapping) for InfluxDB.
It can help with designing the schema and building normal or aggregation queries.
cli.get_fields_as_series(OHLC,
field_aggregations={'close': [AggregationMode.MEAN]},
tags={'symbol': 'AAPL'},
time_range=(start_datetime, end_datetime),
group_by_time_interval='10d')
Disclaimer: I am the author of this library
Upvotes: 0
Reputation: 36
result = client.query("SELECT P_askbid_midprice1 FROM DCIX_OB WHERE time > '2018-01-01'")
this should work
Upvotes: 2