Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Enable debug logging for python requests
import requests
import logging
import httplib
# Debug logging
httplib.HTTPConnection.debuglevel = 1
req_log = logging.getLogger('requests.packages.urllib3')
req_log.propagate = True

This comment has been minimized.

Copy link

@kuznetsov-m kuznetsov-m commented Feb 29, 2020

Hi, @Daenyth!
I found a slightly different way to enable debug logging the logger for requests on the stackoverflow. What do you think about this?

# source:

import requests
import logging
from http.client import HTTPConnection  # py3

log = logging.getLogger('urllib3')

# logging from urllib3 to console
ch = logging.StreamHandler()

# print statements from `http.client.HTTPConnection` to console/stdout
HTTPConnection.debuglevel = 1


This comment has been minimized.

Copy link
Owner Author

@Daenyth Daenyth commented Mar 2, 2020

I'm not up to date on python stuff these days, so I don't really know.


This comment has been minimized.

Copy link

@rca rca commented Jun 19, 2020

The HTTPConnection.debuglevel = 1 statement is magic; thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment