Converts the string to a bytes type, if not already.

    :s: the string to convert to bytes
    :returns: `str` on Python2 and `bytes` on Python3.

def to_bytes(s, encoding="utf-8"):
    """
    Converts the string to a bytes type, if not already.

    :s: the string to convert to bytes
    :returns: `str` on Python2 and `bytes` on Python3.
    """
    if isinstance(s, six.binary_type):
        return s
    else:
        return six.text_type(s).encode(encoding)