How To Disable Logging From The Python Request Library?

Better Stack Team
Updated on October 6, 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)

🔭 Want to centralize and monitor your python logs?

Go to Better Stack and start your log management in 5 minutes.

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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github