import six


def to_bytes(value, encoding='utf-8'):
    """
    Makes sure the value is encoded as a byte string.

    :param value: The Python string value to encode.
    :param encoding: The encoding to use.
    :return: The byte string that was encoded.
    """
    if isinstance(value, six.binary_type):
        return value
    return value.encode(encoding)