import locale


def decodeCPEError(output):
    """Attempts to decode a string with a variety of common encodings."""
    res = None
    encs = [locale.getpreferredencoding(False), 'utf-8', 'latin-1']
    for enc in encs:
        try:
            res = output.decode(enc)
            return res
        except UnicodeDecodeError:
            pass
    return None