Skip to content

Instantly share code, notes, and snippets.

@wsgac
Last active November 30, 2023 12:38
Show Gist options
  • Save wsgac/1851a86f676ff6bea2d686412268b5c9 to your computer and use it in GitHub Desktop.
Save wsgac/1851a86f676ff6bea2d686412268b5c9 to your computer and use it in GitHub Desktop.
How to enable request debugging in Python `requests` library
# Add debugging outputs to requests
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment