Last active
April 6, 2025 14:57
-
-
Save yermulnik/55c46ee560f6693af380254e2d0198c1 to your computer and use it in GitHub Desktop.
Python: debug output for `requests`/`urllib3`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import logging | |
try: | |
import http.client as http_client | |
except ImportError: | |
# Python 2 | |
import httplib as http_client | |
http_client.HTTPConnection.debuglevel = 1 | |
logging.basicConfig() | |
logging.getLogger().setLevel(logging.DEBUG) | |
requests_log = logging.getLogger("requests.packages.urllib3") | |
requests_log.setLevel(logging.DEBUG) | |
requests_log.propagate = True | |
data = { | |
"key": "value", | |
"another_key": "value" | |
} | |
url = "https://host/api/v1/endpoint" | |
headers = {'Accept': 'application/json'} | |
#sess = requests.Session() | |
#sess.trust_env = False # https://github.com/psf/requests/issues/6928 | |
#response = sess.post(url, data=data, headers=headers, verify=True) | |
os.environ['NETRC'] = '' # Another workaround for https://github.com/psf/requests/issues/6928 | |
response = requests.post(url, data=data, headers=headers, verify=True) | |
print(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment