code: def utf8(string):
      
      if isinstance(string, six.text_type):
          return string.encode('utf8')
      elif isinstance(string, six.binary_type):
          return string
      else:
          return six.text_type(string).encode('utf8')
docs: Make sure string is utf8 encoded bytes.
  
      If parameter is a object, object.__str__ will been called before encode as bytes