code: def encode_non_ascii_string(string):
      
      encoded_string = string.encode('utf-8', 'replace')
      if six.PY3:
          encoded_string = encoded_string.decode()
  
      return encoded_string
docs: :param string:
          The string to be encoded
      :type string:
          unicode or str
      :return:
          The encoded string
      :rtype:
          str