Home  >  Q&A  >  body text

Python-requests中, 这一段logging的用法是什么作用 ?

实际现象

预期现象

相关代码

# Set default logging handler to avoid "No handler found" warnings.
import logging
try:  # Python 2.7+
    from logging import NullHandler
except ImportError:
    class NullHandler(logging.Handler):
        def emit(self, record):
            pass

logging.getLogger(__name__).addHandler(NullHandler())

上下文环境

天蓬老师天蓬老师2740 days ago530

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 10:25:03

    This means that if your current version of the logging module does not have a NullHandler, write one yourself. In short, ensure that the subsequent code has a NullHandler available

    reply
    0
  • Cancelreply