From ceb88ac077fad7b801b3fad306826916774a173c Mon Sep 17 00:00:00 2001 From: shoma Date: Fri, 22 Jan 2016 12:47:18 +0900 Subject: [PATCH 1/2] Fix api doc of debug logging for Python 3 --- docs/api.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 8d277c81..44831ae4 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -184,11 +184,12 @@ API Changes import requests import logging - # these two lines enable debugging at httplib level (requests->urllib3->httplib) + # these two lines enable debugging at http.client 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. - import httplib - httplib.HTTPConnection.debuglevel = 1 + from http.client import HTTPConnection # for Python 3 + from httplib import HTTPConnection # for Python 2, httplib is former name of http.client. + HTTPConnection.debuglevel = 1 logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests logging.getLogger().setLevel(logging.DEBUG) From 75c7e5f1c310b19a0b66f75be5e72f4a0ef5821f Mon Sep 17 00:00:00 2001 From: shoma Date: Fri, 22 Jan 2016 13:48:22 +0900 Subject: [PATCH 2/2] Update example for Python 2/3 compatible. --- docs/api.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 44831ae4..b257f5ca 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -184,11 +184,13 @@ API Changes import requests import logging - # these two lines enable debugging at http.client level (requests->urllib3->http.client) + # Enabling debugging at http.client 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. - from http.client import HTTPConnection # for Python 3 - from httplib import HTTPConnection # for Python 2, httplib is former name of http.client. + try: # for Python 3 + from http.client import HTTPConnection + except ImportError: + from httplib import HTTPConnection HTTPConnection.debuglevel = 1 logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests