You need to enable debugging at httplib level ( requests urllib3 httplib ).
Here are some functions for switching ( ..._on() and ..._off() ) or temporarily turning on:
import logging import contextlib try: from http.client import HTTPConnection
Using demo:
>>> requests.get('http://httpbin.org/') <Response [200]> >>> debug_requests_on() >>> requests.get('http://httpbin.org/') INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): httpbin.org DEBUG:requests.packages.urllib3.connectionpool:"GET / HTTP/1.1" 200 12150 send: 'GET / HTTP/1.1\r\nHost: httpbin.org\r\nConnection: keep-alive\r\nAccept- Encoding: gzip, deflate\r\nAccept: */*\r\nUser-Agent: python-requests/2.11.1\r\n\r\n' reply: 'HTTP/1.1 200 OK\r\n' header: Server: nginx ... <Response [200]> >>> debug_requests_off() >>> requests.get('http://httpbin.org/') <Response [200]> >>> with debug_requests(): ... requests.get('http://httpbin.org/') INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): httpbin.org ... <Response [200]>
You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS, but without DATA. The only thing missing is response.body, which is not registered.
Source
Yohann Jul 05 '14 at 16:16 2014-07-05 16:16
source share