I'm using python 2.7. I have a string that when I map to in a dictionary get's encoded. This is the string u'cn-员工股票权益'
and this is the encoded version u'cn-\u5458\u5de5\u80a1\u7968\u6743\u76ca'
. When put it a dictionary for example below it's getting encoded.
Python 2.7
new_dict = {}
new_dict['random_string'] = u'cn-员工股票权益'
new_dict['random_string']
u'cn-\u5458\u5de5\u80a1\u7968\u6743\u76ca'
This is how I'm trying to decode u'cn-\u5458\u5de5\u80a1\u7968\u6743\u76ca'.decode('utf-8')
but I keep on getting the error UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-8: ordinal not in range(128)
I would like to retrieve the original value that was placed in the dictionary and not the encoded value. Using this tool https://www.online-toolz.com/tools/text-unicode-entities-convertor.php
I'm able to decode it back to the original state I wonder what algorithm they're using. I have tried a number of solutions from stack overflow however I haven't been able to achieve the desired results. Solutions I have tried include;