I am in the process of migrating one of my code repo to Python 3.x. I noticed that the redis.StrictRedis class is converting String by string dict to bytes by bytes dict.
# Input
{ u'key': u'value'}
# output
{b'key': b'value'}
Currently, I am fixing this by having a utility method which converts those bytes to string.
def convert_binary_dict_items(values):
# type: (Dict[Any, Any]) -> Dict[Any, Any]
"""
This method convert dictionary items which are of the binary type to string type.
:param values: Dictionary object.
:return:
"""
result = dict()
if not values:
return result
for key, value in six.iteritems(values):
modified_key = key.decode(u'utf-8') if type(key) == bytes else key
modified_value = value.decode(u'utf-8') if type(key) == bytes else value
result[modified_key] = modified_value
return result
Is there a smart solution available? did anyone run into the similar issue?