Requests library
Python
logging
disable log messages
programming tips

How do I disable log messages from the Requests library?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

When requests-related logs are noisy, the fix is usually in Python’s logging configuration rather than in the HTTP call itself. In practice, the messages often come from urllib3, which requests uses underneath, not from the top-level requests logger. The key is to set the level or disable the specific logger that is actually emitting the messages.

Raise the Log Level for urllib3

A common way to silence routine request logs is to raise the logging threshold:

python
1import logging
2
3logging.getLogger("urllib3").setLevel(logging.WARNING)
4logging.getLogger("requests").setLevel(logging.WARNING)

If the noisy messages were only DEBUG or INFO, this is usually enough. The loggers still exist, but low-level chatter is suppressed.

Disable the Logger Completely

If you want to silence the logger entirely, disable it:

python
1import logging
2
3logging.getLogger("urllib3").disabled = True
4logging.getLogger("requests").disabled = True

This is more aggressive than setting a log level. It is useful when you know those messages are never needed in the current process.

A Minimal Working Example

python
1import logging
2import requests
3
4logging.basicConfig(level=logging.INFO)
5logging.getLogger("urllib3").setLevel(logging.WARNING)
6
7response = requests.get("https://httpbin.org/get", timeout=5)
8print(response.status_code)

Here, the application can still log at INFO, but the lower-level HTTP transport messages from urllib3 are pushed up to WARNING and below the visible threshold.

Why urllib3 Usually Matters More Than requests

requests is the public library you call, but the lower-level connection logging often comes from urllib3. If you only silence requests and the messages keep appearing, the real emitter is probably urllib3.

That is why many working examples configure one or both of these loggers:

  • 'requests'
  • 'urllib3'

When in doubt, inspect the logger name in the log output or temporarily print the logging configuration during debugging.

Disable Warnings Versus Disable Logs

Developers sometimes confuse warnings with log records. For example, certificate warnings are not always normal log messages. If the output is a warning rather than a logging event, the solution may be different.

For example, disabling a specific warning looks more like this:

python
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

That suppresses a warning category, not the logger itself. Use the right tool for the kind of output you are seeing.

Centralize the Logging Configuration

If your application has many modules, configure logging once at startup instead of scattering logger tweaks around the codebase.

python
1import logging
2
3def configure_logging() -> None:
4    logging.basicConfig(level=logging.INFO)
5    logging.getLogger("urllib3").setLevel(logging.WARNING)
6    logging.getLogger("requests").setLevel(logging.WARNING)

That keeps behavior consistent and makes it easier to change later. It also prevents a common team-level problem: one script disables a logger entirely while another merely raises the level, so the application behaves differently depending on import order or entry point. Centralizing the rule makes debugging much easier when multiple services or scripts share the same HTTP helper code.

Common Pitfalls

One common mistake is trying to silence requests when the output is actually coming from urllib3. If the wrong logger is targeted, nothing appears to change.

Another mistake is confusing warnings with logs. A certificate or SSL warning may need disable_warnings, not a logger-level change.

Developers also sometimes call logging.basicConfig after other logging configuration has already taken effect, then wonder why the result seems inconsistent.

Finally, suppressing everything can hide useful production diagnostics. It is often better to raise the level to WARNING than to disable the logger entirely unless you are sure the messages are never needed.

Summary

  • Most requests-related noise is controlled through Python logging, often on the urllib3 logger.
  • Use setLevel when you want fewer messages but still want warnings and errors.
  • Use .disabled = True when you want the logger silenced completely.
  • Do not confuse logging output with warning categories.
  • Configure logging centrally so HTTP log behavior stays predictable across the application.

Course illustration
Course illustration

All Rights Reserved.