def _encoded(value, encoding='utf-8'):
 value_type = type(value)
 if (value_type != str):
  if (value_type == six.binary_type):
   value = value.decode(encoding)
  elif (value_type == six.text_type):
   value = value.encode(encoding)
 return value

def _encoded ( value , encoding = 'utf-8' ) : value_type = type ( value ) if ( value_type != str ) : if ( value_type == six . binary_type ) : value = value . decode ( encoding ) elif ( value_type == six . text_type ) : value = value . encode ( encoding ) return value
make sure the value is of type str in both py2 and py3 .