non-ASCII chars not allowed as parameters in cinderclient calls

Bug #1636621 reported by Kenneth Burger
22
This bug affects 3 people
Affects Status Importance Assigned to Milestone
python-cinderclient
Fix Released
Undecided
Michael Dovgal

Bug Description

When using non-ASCII characters in cinderclient calls, I receive the following error"
"'ascii' codec can't encode character u'\xc7' in position 0: ordinal not in range(128)"

It would appear the error lies in cinderclient/base.py, in _build_list_url() method.

query_string = "?%s" % parse.urlencode(params)

While preparing a query string we are using urllib.urlencode(). The urlencode library expects data in str format, and doesn't deal well with Unicode data since it doesn't provide a way to specify an encoding.

It would seem there need to be some upfront processing before passing to the urlencode method, such as:
def encoded_params(params):
    in_dict = dict(params)
    out_dict = {}
    for k, v in in_dict.iteritems():
        if isinstance(v, unicode):
            v = v.encode('utf8')
        elif isinstance(v, str):
            # Must be encoded in UTF-8
            v.decode('utf8')
        out_dict[k] = v
    return list(out_dict.items())

Michael Dovgal (mdovgal)
Changed in python-cinderclient:
assignee: nobody → Michael Dovgal (mdovgal)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-cinderclient (master)

Fix proposed to branch: master
Review: https://review.openstack.org/395684

Changed in python-cinderclient:
status: New → In Progress
Changed in python-cinderclient:
assignee: Michael Dovgal (mdovgal) → Abhishek Sharma M (abhi.sharma)
Revision history for this message
Abhishek Sharma M (abhi.sharma) wrote :

I saw the fix of Michael Dovgal. I had similar fix. Please reassign it to yourself Michael. Sorry for the inconvenience.

Changed in python-cinderclient:
assignee: Abhishek Sharma M (abhi.sharma) → nobody
Michael Dovgal (mdovgal)
Changed in python-cinderclient:
assignee: nobody → Michael Dovgal (mdovgal)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-cinderclient (master)

Reviewed: https://review.openstack.org/395684
Committed: https://git.openstack.org/cgit/openstack/python-cinderclient/commit/?id=797d932d0f564221a9d126d1ca49de36870c62b6
Submitter: Jenkins
Branch: master

commit 797d932d0f564221a9d126d1ca49de36870c62b6
Author: Mykhailo Dovgal <email address hidden>
Date: Wed Nov 9 16:18:09 2016 +0200

    Add convertation of query parameters to string

    There are some problems with non-ascii chars and special symbols
    during using cinderclient.
    This patch closes bug connected with parse.urlencode py27 unicode
    encode bug by adding convertation of query parameters before
    creating query string in manager._build_list_url method.
    Also it fix the problems with encoding in quota commands.

    Change-Id: I96269cca7ad203eaad02d87b30c16d970b26b25f
    Closes-Bug: #1636621
    Closes-Bug: #1518141

Changed in python-cinderclient:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/python-cinderclient 1.11.0

This issue was fixed in the openstack/python-cinderclient 1.11.0 release.

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

Duplicates of this bug

Other bug subscribers

Remote bug watches

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