diff --git a/cinder/api/openstack/wsgi.py b/cinder/api/openstack/wsgi.py index 5e966756ba1..ed93b6caef6 100644 --- a/cinder/api/openstack/wsgi.py +++ b/cinder/api/openstack/wsgi.py @@ -1165,12 +1165,9 @@ class Resource(wsgi.Application): if hasattr(response, 'headers'): for hdr, val in response.headers.items(): # Headers must be utf-8 strings - try: - # python 2.x - response.headers[hdr] = val.encode('utf-8') - except Exception: - # python 3.x - response.headers[hdr] = six.text_type(val) + val = utils.convert_str(val) + + response.headers[hdr] = val if (not request.api_version_request.is_null() and not self._is_legacy_endpoint(request)): diff --git a/cinder/utils.py b/cinder/utils.py index e4bc2978bc8..a501b8295c9 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -836,7 +836,7 @@ def convert_str(text): * convert to Unicode on Python 3: decode bytes from UTF-8 """ if six.PY2: - return encodeutils.safe_encode(text) + return encodeutils.to_utf8(text) else: if isinstance(text, bytes): return text.decode('utf-8')