Skip to content

Commit f8b843b

Browse files
committed
1059-Fixing a bug with multiple json objects
This splits the text by CRLF and then json.loads each part independently instead of attempting the parse the whole string. Signed-off-by: Tristan Escalada <[email protected]>
1 parent 8a6b184 commit f8b843b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

docker/client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,16 @@ def _stream_helper(self, response, decode=False):
251251
if decode:
252252
if six.PY3:
253253
data = data.decode('utf-8')
254-
data = json.loads(data)
255-
yield data
254+
# remove the trailing newline
255+
data = data.strip()
256+
# split the data at any newlines
257+
data_list = data.split("\r\n")
258+
# load and yield each line seperately
259+
for data in data_list:
260+
data = json.loads(data)
261+
yield data
262+
else:
263+
yield data
256264
else:
257265
# Response isn't chunked, meaning we probably
258266
# encountered an error immediately

0 commit comments

Comments
 (0)