@@ -72,8 +72,8 @@ def _build_query_urls(self, ts):
7272 query_urls = []
7373
7474 for measurement in self ._query_measurements :
75- query_urls .append (f'{ self .url } /api/{ measurement } /?{ query_range } ' )
76- logging .debug ("Query: %s" , f' { self . url } / { measurement } /? { query_range } ' )
75+ query_urls .append (f'{ self .url } /api/{ measurement } /?format=json& { query_range } ' )
76+ logging .debug ("Query: %s" , query_urls [ - 1 ] )
7777
7878 return query_urls
7979
@@ -193,15 +193,17 @@ def build_aux_data_record(self, event):
193193 for url in query_urls :
194194 logging .debug ("Query URL: %s" , url )
195195 measurement = os .path .basename (urlparse (url ).path .strip ('/' ))
196- logging . warning ( measurement )
196+
197197 # run the query against the influxDB
198198 try :
199199 response = requests .get (url , timeout = 2 )
200-
201200 if response .status_code != 200 :
202201 logging .error ("Failed to retrieve data. Status code: %s" , response .status_code )
203202
204- response_obj = response .json ()
203+ response_obj = json .loads (response .text )
204+ if isinstance (response_obj , dict ):
205+ response_obj = response_obj .get ('results' , [])
206+
205207 if len (response_obj ):
206208 query_results = {
207209 ** query_results ,
@@ -216,6 +218,8 @@ def build_aux_data_record(self, event):
216218 except json .decoder .JSONDecodeError :
217219 logging .error ("Unable to decode response from URL: %s" , url )
218220 logging .debug (response )
221+ except KeyError :
222+ logging .error ("Something went wrong processing the API response" )
219223
220224 aux_data_record = self ._build_aux_data_dict (event ['id' ], query_results )
221225 return aux_data_record
0 commit comments