def to_bytes(s, encoding='utf-8'):
    """Ensure that s is converted to bytes from the encoding."""
    if hasattr(s, 'encode') and not isinstance(s, bytes):
        s = s.encode(encoding)
    return s