How To Disable Logging From The Python Request Library?

Better Stack Team
Updated on February 3, 2023

You can change the log level of the logger taking care of these messages. Setting the level to WARNING will remove the request messages and keep warnings and errors:

 
import logging

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

In settings.py File

While using Django or other platforms, you can also change the logger in the settings provided by the framework. The following example is from Django:

 
'urllib3': {
        'handlers': ['file'],
        'level': logging.WARNING
    }

If you are new to logging in Django, feel free to read our Django Logging guide to get started.

Better Uptime Dashboard

🔭 Want to centralize and monitor your python logs?

Go to Logtail and start your log management in 5 minutes.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack