<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def coerce_to_bytes(x, charset=sys.getdefaultencoding(), errors='strict'):
 """ Coerce value to bytes Traceback (most recent call last):
 TypeError: Cannot coerce to bytes """

    PY2 = sys.version_info[0] == 2
    if PY2: # pragma: nocover
        if x is None:
            return None
        if isinstance(x, (bytes, bytearray, buffer)):
            return bytes(x)
        if isinstance(x, unicode):
            return x.encode(charset, errors)
        raise TypeError('Cannot coerce to bytes')

    else: # pragma: nocover
        if x is None:
            return None
        if isinstance(x, (bytes, bytearray, memoryview)):
            return bytes(x)
        if isinstance(x, str):
            return x.encode(charset, errors)
        raise TypeError('Cannot coerce to bytes')