I have problem with UnicodeEncodeError in my users_information list:
{u'\u0633\u062a\u064a\u062f@nimbuzz.com': {'UserName': u'\u0633\u062a\u064a\u062f@nimbuzz.com', 'Code': 5, 'Notes': '', 'Active': 0, 'Date': '12/07/2014 14:16', 'Password': '560pL390T', 'Email': u'yuyb0y@gmail.com'}}
And I need to run this code to get users information:
def get_users_info(type, source, parameters):
users_registertion_file = 'static/users_information.txt'
fp = open(users_registertion_file, 'r')
users_information = eval(fp.read())
if parameters:
jid = parameters+"@nimbuzz.com"
if users_information.has_key(jid):
reply(type, source, u"User name:\n" +str(users_information[jid]['UserName'])+ u"\nPassword:\n" +str(users_information[jid]['Password'])+ u"\nREG-code:\nP" +str(users_information[jid]['Code'])+ u"\nDate:\n" +str(users_information[jid]['Date'])+ u"\naccount status:\n " +str(users_information[jid]['Active']))
else:
reply(type, source, u"This user " +parameters+ u" not in user list")
else:
reply(type, source, u"write the id after command")
but when I try to get users information I get this error:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
I try to unicode the jid
using unicode('utf8')
:
jid = parameters.encode('utf8')+"@nimbuzz.com"
but I get the same error:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
Please how I can solve this problem and as you see the UserName key in the users_information list look like:
u'\u0633\u062a\u064a\u062f@nimbuzz.com'
and the users_information list located in txt file.