def fix_unicode_dict(d):
 new_dict = {}
 for (key, value) in d.items():
  if isinstance(value, dict):
   new_dict[key] = fix_unicode_dict(value)
  elif isinstance(value, tuple):
   new_dict[key] = fix_unicode_array(list(value))
  elif isinstance(value, list):
   new_dict[key] = fix_unicode_array(value)
  elif isinstance(value, (str, unicode)):
   new_dict[key] = value.decode('utf-8', 'ignore')
  else:
   new_dict[key] = value
 return new_dict

def fix_unicode_dict ( d ) : new_dict = { } for ( key , value ) in d . items ( ) : if isinstance ( value , dict ) : new_dict [ key ] = fix_unicode_dict ( value ) elif isinstance ( value , tuple ) : new_dict [ key ] = fix_unicode_array ( list ( value ) ) elif isinstance ( value , list ) : new_dict [ key ] = fix_unicode_array ( value ) elif isinstance ( value , ( str , unicode ) ) : new_dict [ key ] = value . decode ( 'utf-8' , 'ignore' ) else : new_dict [ key ] = value return new_dict
this method removes illegal characters recursively from a dictionary .