From 17ecb6891c515511ce33250a3f39f752a9c59b55 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 10 Apr 2013 16:15:28 +0100 Subject: [PATCH 1/2] * Documented the logging, requested in #1297 * Added build directory and *.egg to .gitignore * Added sphinx as setup requirement in order to be able to build documentation with `pyhton setup.py build_sphinx` modified: .gitignore modified: docs/api.rst modified: setup.py --- .gitignore | 2 ++ docs/api.rst | 20 +++++++++++++++++--- setup.py | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a88418dbbc..e1ea2a6096 100644 --- a/.gitignore +++ b/.gitignore @@ -7,10 +7,12 @@ pylint.txt toy.py violations.pyflakes.txt cover/ +build/ docs/_build requests.egg-info/ *.pyc *.swp +*.egg env/ .workon diff --git a/docs/api.rst b/docs/api.rst index 771d7a8274..dce19d3e42 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -165,9 +165,23 @@ API Changes :: - # Verbosity should now be configured with logging - my_config = {'verbose': sys.stderr} - requests.get('http://httpbin.org/headers', config=my_config) # bad! + import requests + import logging + + # these two lines enable debugging at httplib level (requests->urllib3->httplib) + # 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 + + logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests + logging.getLogger().setLevel(logging.DEBUG) + requests_log = logging.getLogger("requests") + requests_log.setLevel(logging.DEBUG) + requests_log.propagate = True + + requests.get('http://httpbin.org/headers') + Licensing diff --git a/setup.py b/setup.py index 52dfe025a8..64e305bcc5 100755 --- a/setup.py +++ b/setup.py @@ -39,6 +39,7 @@ package_dir={'requests': 'requests'}, include_package_data=True, install_requires=requires, + setup_requires=['sphinx'], license=open('LICENSE').read(), zip_safe=False, classifiers=( From fb49481ddfae75840271bbeff5987a791170d76d Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 10 Apr 2013 16:46:05 +0100 Subject: [PATCH 2/2] Updated documentation indicating that logging is done via requests.packages.urllib3 instead of requests. modified: docs/api.rst --- docs/api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index dce19d3e42..89733a29a2 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -176,7 +176,7 @@ API Changes logging.basicConfig() # you need to initialize logging, otherwise you will not see anything from requests logging.getLogger().setLevel(logging.DEBUG) - requests_log = logging.getLogger("requests") + requests_log = logging.getLogger("requests.packages.urllib3") requests_log.setLevel(logging.DEBUG) requests_log.propagate = True