8000 Merge pull request #166 from georgijd/fix-issue-164 · krishnazure/influxdb-python@4843bce · GitHub
[go: up one dir, main page]

Skip to content {"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}

Commit 4843bce

Browse files
committed
Merge pull request influxdata#166 from georgijd/fix-issue-164
Fix issue influxdata#164 (Thanks @georgijd !)
2 parents c849fe1 + a69bc78 commit 4843bce

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

influxdb/influxdb08/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,13 @@ def _query(self, query, time_precision='s', chunked=False):
448448
)
449449

450450
if chunked:
451-
return list(chunked_json.loads(response.content.decode()))
451+
decoded = {}
452+
try:
453+
decoded = chunked_json.loads(response.content.decode())
454+
except UnicodeDecodeError:
455+
decoded = chunked_json.loads(response.content.decode('utf-8'))
456+
finally:
457+
return list(decoded)
452458
else:
453459
return response.json()
454460

tests/influxdb/influxdb08/client_test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
from influxdb.influxdb08 import InfluxDBClient
1818
from influxdb.influxdb08.client import session
1919

20+
import sys
21+
if sys.version < '3':
22+
import codecs
23+
24+
def u(x):
25+
return codecs.unicode_escape_decode(x)[0]
26+
else:
27+
def u(x):
28+
return x
29+
2030

2131
def _build_response_object(status_code=200, content=""):
2232
resp = requests.Response()
@@ -366,6 +376,35 @@ def test_query_chunked(self):
366376
[example_object, example_object]
367377
)
368378

379+
def test_query_chunked_unicode(self):
380+
cli = InfluxDBClient(database='db')
381+
example_object = {
382+
'points': [
383+
[1415206212980, 10001, u('unicode-\xcf\x89')],
384+
[1415197271586, 10001, u('more-unicode-\xcf\x90')]
385+
],
386+
'name': 'foo',
387+
'columns': [
388+
'time',
389+
'sequence_number',
390+
'val'
391+
]
392+
}
393+
example_response = \
394+
json.dumps(example_object) + json.dumps(example_object)
395+
396+
with requests_mock.Mocker() as m:
397+
m.register_uri(
398+
requests_mock.GET,
399+
"http://localhost:8086/db/db/series",
400+
text=example_response
401+
)
402+
403+
self.assertListEqual(
404+
cli.query('select * from foo', chunked=True),
405+
[example_object, example_object]
406+
)
407+
369408
@raises(Exception)
370409
def test_query_fail(self):
371410
with _mocked_session('get', 401):

0 commit comments

Comments
 (0)
0