Reduce requests and urllib3 log noise in Python

Set requests and urllib3 logger thresholds, understand inherited levels and propagation, and keep useful HTTP warnings visible without hiding application exceptions.

Best practices
Python programming and application logging

Most connection-pool debug messages seen when using Requests come from urllib3. Set its logger to WARNING to suppress ordinary DEBUG and INFO records while allowing warning and higher-severity records.

import logging

logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("requests").setLevel(logging.WARNING)

Configure this after your application's general logging setup. Setting the requests logger can cover records using that namespace, but it does not control the separate urllib3 logger hierarchy.

Understand inherited levels

urllib3.connectionpool is a child of urllib3. When its level is NOTSET, it inherits an effective threshold from its ancestors, so setting urllib3 to WARNING normally suppresses its DEBUG records.

An explicitly configured child level can override that inheritance. Moreover, once a record propagates to ancestor handlers, those ancestor loggers' levels are not reapplied. Check both the emitting logger's level and the relevant handler levels when output is unexpected.

logging.getLogger("urllib3.connectionpool").setLevel(logging.WARNING)

Use the more specific setting if that child has been explicitly enabled elsewhere; inspect the configuration rather than adding it blindly throughout the application.

Configure Django logging

This is a complete minimal console configuration for settings.py; merge it deliberately with your existing handlers:

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {"console": {"class": "logging.StreamHandler"}},
    "loggers": {
        "urllib3": {
            "handlers": ["console"],
            "level": "WARNING",
            "propagate": False,
        },
        "requests": {
            "handlers": ["console"],
            "level": "WARNING",
            "propagate": False,
        },
    },
}

A file handler can replace the console handler if it is defined and writable. propagate=False avoids sending these records to root handlers as well.

FAQ

Why do I still see output? Check child logger levels, handler filters, and later configuration changes. Raw http.client debug output and Python warnings are separate mechanisms; a logger level alone does not necessarily suppress them. Setting the root logger to DEBUG does not by itself override an explicit child namespace threshold.

Will real failures remain visible? WARNING and higher records that pass the rest of the logging configuration remain eligible for output. However, Requests can raise connection and timeout exceptions without logging an ERROR record for you. Handle or log those exceptions at the application boundary.

Can I silence just one request temporarily? You can save, change, and restore a level, but logger configuration is shared across threads and tasks. That temporary change can affect other concurrent requests, so prefer stable configuration when possible.

References

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting