image-download output to stdout fails with Python 3

Bug #1528083 reported by Andy Botting on 2015-12-21
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance Client
Undecided
Unassigned
Liberty
Undecided
Flavio Percoco

Bug Description

When using image-download with Python3 and outputting to stdout, I get the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/glanceclient/shell.py", line 605, in main
    args.func(client, args)
  File "/usr/lib/python3.5/site-packages/glanceclient/v2/shell.py", line 281, in do_image_download
    utils.save_image(body, args.file)
  File "/usr/lib/python3.5/site-packages/glanceclient/common/utils.py", line 307, in save_image
    image.write(chunk)
TypeError: write() argument must be str, not bytes

This this due to Python 3 requiring a string when printing directly to stdout, whereas Python 2 allowed either string or bytes.

A good description of the issue is documented here:
http://bugs.python.org/issue18512

I think the easiest fix for this is to test for sys.stdout.buffer which should be used for Python 3, then fall back to sys.stdout if it's not available.

I've put up a review to fix this:
https://review.openstack.org/#/c/259825/

Changed in python-glanceclient:
status: New → Confirmed

Reviewed: https://review.openstack.org/259825
Committed: https://git.openstack.org/cgit/openstack/python-glanceclient/commit/?id=3caeb4504e7f96130f904356bf45f93fcd7834c6
Submitter: Jenkins
Branch: master

commit 3caeb4504e7f96130f904356bf45f93fcd7834c6
Author: Andy Botting <email address hidden>
Date: Mon Dec 21 12:18:08 2015 +1100

    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

Changed in python-glanceclient:
status: Confirmed → Fix Released

Reviewed: https://review.openstack.org/260687
Committed: https://git.openstack.org/cgit/openstack/python-glanceclient/commit/?id=4449ed306f53e4cefa981d895c84eb242df13202
Submitter: Jenkins
Branch: stable/liberty

commit 4449ed306f53e4cefa981d895c84eb242df13202
Author: Andy Botting <email address hidden>
Date: Mon Dec 21 12:18:08 2015 +1100

    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
    (cherry picked from commit 3caeb4504e7f96130f904356bf45f93fcd7834c6)

This issue was fixed in the openstack/python-glanceclient 2.0.0 release.

This issue was fixed in the openstack/python-glanceclient 1.1.1 release.

This issue was fixed in the openstack/python-glanceclient 1.1.1 release.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.