From 3caeb4504e7f96130f904356bf45f93fcd7834c6 Mon Sep 17 00:00:00 2001 From: Andy Botting Date: Mon, 21 Dec 2015 12:18:08 +1100 Subject: [PATCH] Fix image-download to stdout on Python 3.x Glance image-download to stdout fails on Python3 due to sys.stdout.write not allowing bytes to be written directly. A good description of the issue is listed at http://bugs.python.org/issue18512 Closes-Bug: #1528083 Change-Id: I2963914e2e0744410267b5735ff77939413916d4 --- glanceclient/common/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index 88144ef8..e7c0992e 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -298,7 +298,10 @@ def save_image(data, path): :param path: path to save the image to """ if path is None: - image = sys.stdout + if six.PY3: + image = sys.stdout.buffer + else: + image = sys.stdout else: image = open(path, 'wb') try: