def to_bytes(str_or_bytes):
    """
        转换 str_or_bytes 为 bytes

        - if hasattr(str_or_bytes, 'encode'), 转换

    :param str_or_bytes:
    :return:
    """
    return str_or_bytes.encode() if hasattr(str_or_bytes, 'encode'
        ) else str_or_bytes
