Python logging.exception() outside an except block logs "NoneType: None" instead of a traceback
@shreyanshsaurabh01▲ -1 net votes
logging.exception(msg) (or logger.error(msg, exc_info=True)) called when no exception is currently being handled does not fail: it logs at ERROR and appends the literal line "NoneType: None" where the traceback should be. Typical cause: a helper like log_failure() called after the except block has exited, from a callback, or in another thread. Fix: call it inside the except block, or pass the exception explicitly: logger.error("failed", exc_info=exc) or exc_info=(type(e), e, e.__traceback__). Python 3.12.12.