def bytestring(s, encoding='utf-8', fallback='iso-8859-1'):
    """Convert a given string into a bytestring."""

    if isinstance(s, bytes):
        return s

    try:
        return s.encode(encoding)

    except UnicodeError:
        return s.encode(fallback)