为什么我无法使用 python 查询 Influxdbv2 数据?
Why I cannot query Influxdbv2 data using python?
我正在尝试使用 python3 从 InfluxDBv2 (2.0.2) 查询数据。查询是不断变化的,它在 InfluxDB 中运行良好(它能很好地显示数据)。我尝试在同一个 VM (Ubuntu 18.04) 和主机 (Windows10 Jupyter python-kernel=python3).
中执行
!pip install influxdb-client
!pip install pandas
import pandas as pd
from influxdb_client import InfluxDBClient
client = InfluxDBClient(url="http://192.168.1.55:9999", token="RQrupr_Za863NcxjbWDWpVWgdgsgshwawkfYuPrc02tTvwCxwYOHywb_huoK4EttYY4pPOPr3Vcfv-7xo8cBlldw==", org="bim")
query_api=client.query_api()
data_frame = query_api.query_data_frame('from(bucket:"manager") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "mqtt_consumer") |> filter(fn: (r) => r["_field"] == "timestamp") |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) |> yield(name: "mean")')
data_frame.head()
r@r-VirtualBox:~$ python qr.py
Traceback (most recent call last):
File "qr.py", line 8, in <module>
data_frame = query_api.query_data_frame('from(bucket:"manager") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "mqtt_consumer") |> filter(fn: (r) => r["_field"] == "timestamp") |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) |> yield(name: "mean")')
File "/home//.local/lib/python3.6/site-packages/influxdb_client/client/query_api.py", line 116, in query_data_frame
_generator = self.query_data_frame_stream(query, org=org, data_frame_index=data_frame_index)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/client/query_api.py", line 141, in query_data_frame_stream
async_req=False, _preload_content=False, _return_http_data_only=False)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/service/query_service.py", line 260, in post_query
(data) = self.post_query_with_http_info(**kwargs) # noqa: E501
File "/home/.local/lib/python3.6/site-packages/influxdb_client/service/query_service.py", line 355, in post_query_with_http_info
urlopen_kw=urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/api_client.py", line 345, in call_api
_preload_content, _request_timeout, urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/api_client.py", line 174, in __call_api
_request_timeout=_request_timeout, **urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/api_client.py", line 392, in request
**urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/rest.py", line 309, in POST
**urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/rest.py", line 252, in request
raise ApiException(http_resp=r)
influxdb_client.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'Vary': 'Accept-Encoding', 'X-Platform-Error-Code': 'invalid', 'Date': 'Fri, 18 Dec 2020 08:06:28 GMT', 'Transfer-Encoding': 'chunked'})
HTTP response body: b'{"code":"invalid","message":"error @1:219-1:220: undefined identifier v"}'
我错过了什么吗?我关注了这个官方网站的示例 https://github.com/influxdata/influxdb-client-python#pandas-dataframe
你读错了吗?
{"code":"invalid","message":"error @1:219-1:220: undefined identifier v"}
您的查询是
from(bucket:"manager") |>
range(start: v.timeRangeStart, stop: v.timeRangeStop) |>
filter(fn: (r) => r["_measurement"] == "mqtt_consumer") |>
filter(fn: (r) => r["_field"] == "timestamp") |>
aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) |>
yield(name: "mean")
然而您从未以任何方式定义 range
和 aggregateWindow
子句中使用的 v
变量。
它们可能在其他一些 InfluxDB 客户端中工作,因为其 UI 定义了它们并可能在将它们传递给 InfluxDB 服务器之前将它们替换到查询中。
我正在尝试使用 python3 从 InfluxDBv2 (2.0.2) 查询数据。查询是不断变化的,它在 InfluxDB 中运行良好(它能很好地显示数据)。我尝试在同一个 VM (Ubuntu 18.04) 和主机 (Windows10 Jupyter python-kernel=python3).
中执行!pip install influxdb-client
!pip install pandas
import pandas as pd
from influxdb_client import InfluxDBClient
client = InfluxDBClient(url="http://192.168.1.55:9999", token="RQrupr_Za863NcxjbWDWpVWgdgsgshwawkfYuPrc02tTvwCxwYOHywb_huoK4EttYY4pPOPr3Vcfv-7xo8cBlldw==", org="bim")
query_api=client.query_api()
data_frame = query_api.query_data_frame('from(bucket:"manager") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "mqtt_consumer") |> filter(fn: (r) => r["_field"] == "timestamp") |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) |> yield(name: "mean")')
data_frame.head()
r@r-VirtualBox:~$ python qr.py
Traceback (most recent call last):
File "qr.py", line 8, in <module>
data_frame = query_api.query_data_frame('from(bucket:"manager") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r["_measurement"] == "mqtt_consumer") |> filter(fn: (r) => r["_field"] == "timestamp") |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) |> yield(name: "mean")')
File "/home//.local/lib/python3.6/site-packages/influxdb_client/client/query_api.py", line 116, in query_data_frame
_generator = self.query_data_frame_stream(query, org=org, data_frame_index=data_frame_index)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/client/query_api.py", line 141, in query_data_frame_stream
async_req=False, _preload_content=False, _return_http_data_only=False)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/service/query_service.py", line 260, in post_query
(data) = self.post_query_with_http_info(**kwargs) # noqa: E501
File "/home/.local/lib/python3.6/site-packages/influxdb_client/service/query_service.py", line 355, in post_query_with_http_info
urlopen_kw=urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/api_client.py", line 345, in call_api
_preload_content, _request_timeout, urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/api_client.py", line 174, in __call_api
_request_timeout=_request_timeout, **urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/api_client.py", line 392, in request
**urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/rest.py", line 309, in POST
**urlopen_kw)
File "/home/.local/lib/python3.6/site-packages/influxdb_client/rest.py", line 252, in request
raise ApiException(http_resp=r)
influxdb_client.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json; charset=utf-8', 'Vary': 'Accept-Encoding', 'X-Platform-Error-Code': 'invalid', 'Date': 'Fri, 18 Dec 2020 08:06:28 GMT', 'Transfer-Encoding': 'chunked'})
HTTP response body: b'{"code":"invalid","message":"error @1:219-1:220: undefined identifier v"}'
我错过了什么吗?我关注了这个官方网站的示例 https://github.com/influxdata/influxdb-client-python#pandas-dataframe
你读错了吗?
{"code":"invalid","message":"error @1:219-1:220: undefined identifier v"}
您的查询是
from(bucket:"manager") |>
range(start: v.timeRangeStart, stop: v.timeRangeStop) |>
filter(fn: (r) => r["_measurement"] == "mqtt_consumer") |>
filter(fn: (r) => r["_field"] == "timestamp") |>
aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) |>
yield(name: "mean")
然而您从未以任何方式定义 range
和 aggregateWindow
子句中使用的 v
变量。
它们可能在其他一些 InfluxDB 客户端中工作,因为其 UI 定义了它们并可能在将它们传递给 InfluxDB 服务器之前将它们替换到查询中。