diff --git a/CHANGELOG.md b/CHANGELOG.md index c3125435..6b2d35f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Bug Fixes 1. [#601](https://github.com/influxdata/influxdb-client-python/pull/601): Use HTTResponse.headers to clear deprecation warning [urllib3] +2. [#569](https://github.com/influxdata/influxdb-client-python/pull/569): Return `str` instead of `urllib3.HTTPResponse` for `InfluxDBClient.QueryAPI.query_raw`. + ### Documentation 1. [#566](https://github.com/influxdata/influxdb-client-python/pull/566): Fix Sphinx documentation build and add support `.readthedocs.yml` V2 configuration file diff --git a/influxdb_client/client/query_api.py b/influxdb_client/client/query_api.py index f1df2041..a6d89b1f 100644 --- a/influxdb_client/client/query_api.py +++ b/influxdb_client/client/query_api.py @@ -9,6 +9,7 @@ from influxdb_client import Dialect from influxdb_client.client._base import _BaseQueryApi from influxdb_client.client.flux_table import FluxRecord, TableList, CSVIterator +from influxdb_client.rest import _UTF_8_encoding class QueryOptions(object): @@ -121,8 +122,8 @@ def query_raw(self, query: str, org=None, dialect=_BaseQueryApi.default_dialect, org = self._org_param(org) result = self._query_api.post_query(org=org, query=self._create_query(query, dialect, params), async_req=False, _preload_content=False) - - return result + raw_bytes = result.data + return raw_bytes.decode(_UTF_8_encoding) def query(self, query: str, org=None, params: dict = None) -> TableList: """Execute synchronous Flux query and return result as a :class:`~influxdb_client.client.flux_table.FluxTable` list. diff --git a/tests/test_InfluxDBClient.py b/tests/test_InfluxDBClient.py index ca37291b..aea7c0ab 100644 --- a/tests/test_InfluxDBClient.py +++ b/tests/test_InfluxDBClient.py @@ -1,4 +1,3 @@ -import codecs import http.server import json import logging @@ -346,7 +345,8 @@ def test_query_and_debug(self): self.assertIn("my-bucket", list(map(lambda record: record["name"], results[0].records))) # Query RAW results = self.client.query_api().query_raw("buckets()", "my-org") - self.assertIn("my-bucket", codecs.decode(results.data)) + self.assertIn("my-bucket", results) + self.assertTrue(isinstance(results, str)) # Bucket API results = self.client.buckets_api().find_buckets() self.assertIn("my-bucket", list(map(lambda bucket: bucket.name, results.buckets)))