How To Log All Requests From The Python Request Library?

Better Stack Team
Updated on May 4, 2022

You need to use urllib3 logger and set the log level to DEBUG:

log = logging.getLogger('urllib3')


To maximise the message you can get, set HTTPConnection.debuglevel to 1:

from http.client import HTTPConnection
HTTPConnection.debuglevel = 1

By using the additional method, that cannot be captured by logging, you need to settle for console output.

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