Skip to content

Instantly share code, notes, and snippets.

@kodekracker
Created July 19, 2022 17:40
Show Gist options
  • Save kodekracker/6177e6e05cbd9835bdf28f6c738d5f68 to your computer and use it in GitHub Desktop.
Save kodekracker/6177e6e05cbd9835bdf28f6c738d5f68 to your computer and use it in GitHub Desktop.
Enable debugging in python requests package
# source: https://stackoverflow.com/a/57325050/10504918
import requests
import logging
from http.client import HTTPConnection # py3
log = logging.getLogger('urllib3')
log.setLevel(logging.DEBUG)
# logging from urllib3 to console
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
log.addHandler(ch)
# print statements from `http.client.HTTPConnection` to console/stdout
HTTPConnection.debuglevel = 1
requests.get('http://httpbin.org/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment