def _yaml_result_unicode_to_utf8(data):
 if six.PY3:
  return data
 if isinstance(data, OrderedDict):
  for (key, elt) in six.iteritems(data):
   data[key] = _yaml_result_unicode_to_utf8(elt)
 elif isinstance(data, list):
  for i in range(len(data)):
   data[i] = _yaml_result_unicode_to_utf8(data[i])
 elif isinstance(data, six.text_type):
  data = data.encode('utf-8')
 return data

def _yaml_result_unicode_to_utf8 ( data ) : if six . PY3 : return data if isinstance ( data , OrderedDict ) : for ( key , elt ) in six . iteritems ( data ) : data [ key ] = _yaml_result_unicode_to_utf8 ( elt ) elif isinstance ( data , list ) : for i in range ( len ( data ) ) : data [ i ] = _yaml_result_unicode_to_utf8 ( data [ i ] ) elif isinstance ( data , six . text_type ) : data = data . encode ( 'utf-8' ) return data
replace unicode strings by utf-8 str in final yaml result this is a recursive function .