Source From Here
Question
In my case, I'm using the requests library to call PayPal's API over HTTPS. Unfortunately, I'm getting an error from PayPal, and PayPal support cannot figure out what the error is or what's causing it. They want me to "Please provide the entire request, headers included".
How can I do that?
How-To
A simple method: enable logging in recent versions of Requests (1.x and higher.)
Requests uses the http.client and logging module configuration to control logging verbosity, as described here.
Demonstration
Code excerpted from the linked documentation:
Example Output
Question
In my case, I'm using the requests library to call PayPal's API over HTTPS. Unfortunately, I'm getting an error from PayPal, and PayPal support cannot figure out what the error is or what's causing it. They want me to "Please provide the entire request, headers included".
How can I do that?
How-To
A simple method: enable logging in recent versions of Requests (1.x and higher.)
Requests uses the http.client and logging module configuration to control logging verbosity, as described here.
Demonstration
Code excerpted from the linked documentation:
- import requests
- 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
- requests.get('https://httpbin.org/headers')
沒有留言:
張貼留言