8
8
from influxdb_client .client ._base import _BaseQueryApi
9
9
from influxdb_client .client .flux_table import FluxRecord , TableList
10
10
from influxdb_client .client .query_api import QueryOptions
11
- from influxdb_client .rest import _UTF_8_encoding
11
+ from influxdb_client .rest import _UTF_8_encoding , ApiException
12
+ from .._async .rest import RESTResponseAsync
12
13
13
14
14
15
class QueryApiAsync (_BaseQueryApi ):
@@ -98,10 +99,7 @@ async def query(self, query: str, org=None, params: dict = None) -> TableList:
98
99
""" # noqa: E501
99
100
org = self ._org_param (org )
100
101
101
- response = await self ._query_api .post_query_async (org = org ,
102
- query = self ._create_query (query , self .default_dialect , params ),
103
- async_req = False , _preload_content = False ,
104
- _return_http_data_only = True )
102
+ response = await self ._post_query (org = org , query = self ._create_query (query , self .default_dialect , params ))
105
103
106
104
return await self ._to_tables_async (response , query_options = self ._get_query_options ())
107
105
@@ -118,10 +116,7 @@ async def query_stream(self, query: str, org=None, params: dict = None) -> Async
118
116
""" # noqa: E501
119
117
org = self ._org_param (org )
120
118
121
- response = await self ._query_api .post_query_async (org = org ,
122
- query = self ._create_query (query , self .default_dialect , params ),
123
- async_req = False , _preload_content = False ,
124
- _return_http_data_only = True )
119
+ response = await self ._post_query (org = org , query = self ._create_query (query , self .default_dialect , params ))
125
120
126
121
return await self ._to_flux_record_stream_async (response , query_options = self ._get_query_options ())
127
122
@@ -193,11 +188,8 @@ async def query_data_frame_stream(self, query: str, org=None, data_frame_index:
193
188
""" # noqa: E501
194
189
org = self ._org_param (org )
195
190
196
- response = await self ._query_api .post_query_async (org = org ,
197
- query = self ._create_query (query , self .default_dialect , params ,
198
- dataframe_query = True ),
199
- async_req = False , _preload_content = False ,
200
- _return_http_data_only = True )
191
+ response = await self ._post_query (org = org , query = self ._create_query (query , self .default_dialect , params ,
192
+ dataframe_query = True ))
201
193
202
194
return await self ._to_data_frame_stream_async (data_frame_index = data_frame_index , response = response ,
203
195
query_options = self ._get_query_options ())
@@ -215,8 +207,18 @@ async def query_raw(self, query: str, org=None, dialect=_BaseQueryApi.default_di
215
207
:return: :class:`~str`
216
208
"""
217
209
org = self ._org_param (org )
218
- result = await self ._query_api .post_query_async (org = org , query = self ._create_query (query , dialect , params ),
219
- async_req = False , _preload_content = False ,
220
- _return_http_data_only = True )
210
+ result = await self ._post_query (org = org , query = self ._create_query (query , dialect , params ))
221
211
raw_bytes = await result .read ()
222
212
return raw_bytes .decode (_UTF_8_encoding )
213
+
214
+ async def _post_query (self , org , query ):
215
+ response = await self ._query_api .post_query_async (org = org ,
216
+ query = query ,
217
+ async_req = False ,
218
+ _preload_content = False ,
219
+ _return_http_data_only = True )
220
+ if not 200 <= response .status <= 299 :
221
+ data = await response .read ()
222
+ raise ApiException (http_resp = RESTResponseAsync (response , data ))
223
+
224
+ return response
0 commit comments