0

我有这段代码来查询流入数据库,但它根本不起作用。这是python代码。

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';")

我收到以下错误,但仍不清楚如何修复上面的代码。如果我使用 bash 直接从 influxdb 查询,SELECT P_askbid_midprice1 FROM 'DCIX_OB' WHERE time > '2018-01-01';它工作得非常好。

    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"}

我该如何解决?

4

2 回答 2

2

result = client.query("SELECT P_askbid_midprice1 FROM DCIX_OB WHERE time > '2018-01-01'")

这应该工作

于 2018-05-17T22:38:54.107 回答
0

您也许可以使用Pinform,它是 InfluxDB 的某种 ORM/OSTM(对象时间序列映射)。

它可以帮助设计架构和构建普通或聚合查询。

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')

免责声明:我是这个库的作者

于 2019-02-11T12:45:27.567 回答