diff options
author | Tristan Escalada <tristan@escalada.us> | 2016-05-26 21:56:34 -0400 |
---|---|---|
committer | Tristan Escalada <tristan@escalada.us> | 2016-08-01 11:05:32 -0400 |
commit | f8b843b127a99dc329b9da7da4bedc050be36ebf (patch) | |
tree | 3f9cec960fc1fa4677c0fa6344f186ffe4baeda6 | |
parent | 8a6b1843c33a5956a09c04a68305be9b116b0b6a (diff) | |
download | docker-py-f8b843b127a99dc329b9da7da4bedc050be36ebf.tar.gz |
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 <tristan@escalada.us>
-rw-r--r-- | docker/client.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/docker/client.py b/docker/client.py index c3e5874..de67dbe 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 |