def _formatTraceback(failure):
    """
    Format a failure traceback, assuming UTF-8 and using a replacement
    strategy for errors.  Every effort is made to provide a usable
    traceback, but should not that not be possible, a message and the
    captured exception are logged.

    @param failure: The failure to retrieve a traceback from.
    @type failure: L{twisted.python.failure.Failure}

    @return: The formatted traceback.
    @rtype: L{unicode}
    """
    try:
        traceback = failure.getTraceback()
        if isinstance(traceback, bytes):
            traceback = traceback.decode('utf-8', errors='replace')
    except BaseException as e:
        traceback = (
            u"(UNABLE TO OBTAIN TRACEBACK FROM EVENT):" + unicode(e)
        )
    return traceback

    Format a failure traceback, assuming UTF-8 and using a replacement
    strategy for errors.  Every effort is made to provide a usable
    traceback, but should not that not be possible, a message and the
    captured exception are logged.

    @param failure: The failure to retrieve a traceback from.
    @type failure: L{twisted.python.failure.Failure}

    @return: The formatted traceback.
    @rtype: L{unicode}
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/logger/_format.py