The following error is reported when creating a volume snapshot with non-ascii display-description, e.g. cinder snapshot-create --display-description "中文" my-2nd-volume.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher [req-81f48a02-b1ef-4aae-9e22-ac2ce1c75b2f 16818cbff07548889da69bf526558d97 7aac0111a39741f59513c05b2d83dd70 - - -] Exception during message handling: 'ascii' codec can't encode characters in position 111-117: ordinal not in range(128)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher Traceback (most recent call last):
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 142, in _dispatch_and_reply
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher executor_callback))
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 186, in _dispatch
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher executor_callback)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 129, in _do_dispatch
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher result = func(ctxt, **new_args)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/osprofiler/profiler.py", line 102, in wrapper
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher info["function"]["kwargs"] = str(kwargs)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher UnicodeEncodeError: 'ascii' codec can't encode characters in position 111-117: ordinal not in range(128)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher
Root cause is that profiler tries to get a string representation of the arguments (cinder.objects.snapshot.Snapshot) of the snapshot create cinder volume service api. As a result, VersionedObject.__repr__ will be called to produce such a string representation with an attribute (display-description) containing non-ascii characters, thus returning an unicode object. However when __repr__ returns an unicode object, it's expected that the the returned string can be encoded by default encoding scheme which is ascii in general [1][2]. So __repr__ needs to make sure any unicode string it's going to return are properly encoded.
The following error is reported when creating a volume snapshot with non-ascii display- description, e.g. cinder snapshot-create --display- description "中文" my-2nd-volume.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging. rpc.dispatcher [req-81f48a02- b1ef-4aae- 9e22-ac2ce1c75b 2f 16818cbff075488 89da69bf526558d 97 7aac0111a39741f 59513c05b2d83dd 70 - - -] Exception during message handling: 'ascii' codec can't encode characters in position 111-117: ordinal not in range(128) rpc.dispatcher Traceback (most recent call last): rpc.dispatcher File "/usr/lib/ python2. 7/dist- packages/ oslo_messaging/ rpc/dispatcher. py", line 142, in _dispatch_and_reply rpc.dispatcher executor_callback)) rpc.dispatcher File "/usr/lib/ python2. 7/dist- packages/ oslo_messaging/ rpc/dispatcher. py", line 186, in _dispatch rpc.dispatcher executor_callback) rpc.dispatcher File "/usr/lib/ python2. 7/dist- packages/ oslo_messaging/ rpc/dispatcher. py", line 129, in _do_dispatch rpc.dispatcher result = func(ctxt, **new_args) rpc.dispatcher File "/usr/lib/ python2. 7/dist- packages/ osprofiler/ profiler. py", line 102, in wrapper rpc.dispatcher info["function" ]["kwargs" ] = str(kwargs) rpc.dispatcher UnicodeEncodeError: 'ascii' codec can't encode characters in position 111-117: ordinal not in range(128) rpc.dispatcher
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.
Root cause is that profiler tries to get a string representation of the arguments (cinder. objects. snapshot. Snapshot) of the snapshot create cinder volume service api. As a result, VersionedObject .__repr_ _ will be called to produce such a string representation with an attribute (display- description) containing non-ascii characters, thus returning an unicode object. However when __repr__ returns an unicode object, it's expected that the the returned string can be encoded by default encoding scheme which is ascii in general [1][2]. So __repr__ needs to make sure any unicode string it's going to return are properly encoded.
[1] trying to encode the returned string when it's an unicode object /github. com/python/ cpython/ blob/2. 7/Objects/ object. c#L387
https:/
[2] if encoding arg is left null, default encoding will be used /github. com/python/ cpython/ blob/2. 7/Objects/ unicodeobject. c#L1355
https:/