From f8b843b127a99dc329b9da7da4bedc050be36ebf Mon Sep 17 00:00:00 2001 From: Tristan Escalada Date: Thu, 26 May 2016 21:56:34 -0400 Subject: [PATCH] 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 --- docker/client.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docker/client.py b/docker/client.py index c3e5874e..de67dbe4 100644 --- a/docker/client.py +++ b/docker/client.py @@ -251,8 +251,16 @@ class Client( if decode: if six.PY3: data = data.decode('utf-8') - data = json.loads(data) - yield data + # remove the trailing newline + data = data.strip() + # split the data at any newlines + data_list = data.split("\r\n") + # load and yield each line seperately + for data in data_list: + data = json.loads(data) + yield data + else: + yield data else: # Response isn't chunked, meaning we probably # encountered an error immediately