Skip to content

Instantly share code, notes, and snippets.

@ubershmekel
Created August 30, 2015 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ubershmekel/e5fb719bbe9fd27473e6 to your computer and use it in GitHub Desktop.
Save ubershmekel/e5fb719bbe9fd27473e6 to your computer and use it in GitHub Desktop.
This will cause the requests module to print out anything it's doing
"""
Thank you
http://stackoverflow.com/a/24588289/177498
"""
def debug():
import logging
# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
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