import six


def encode_string(s, encoding='utf-8', errors='strict'):
    """Encode string s to bytes."""
    if isinstance(s, bytes):
        return s
    if isinstance(s, six.text_type):
        s = s.encode(encoding, errors=errors)
    else:
        s = str(s).encode(encoding, errors=errors)
    return s