From 75c7e5f1c310b19a0b66f75be5e72f4a0ef5821f Mon Sep 17 00:00:00 2001 From: shoma Date: Fri, 22 Jan 2016 13:48:22 +0900 Subject: [PATCH] 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