python

Patching requests HTTP hooks with custom arguments

May 7, 2020
blog
python

I am working on a project where we have lots of functions integrated with external APIs. Functions where HTTP requests get dispatched, we log the current caller’s name, headers, and data (if any) in case we need to debug anything. For example: import logging import requests LOGGER = logging.getLogger("external") def create_external_services(): ... LOGGER.info(f"[func] | Request {data}") response = requests.post("..") LOGGER.info(f"[func] | Response {response.status_code} {response.text}") ... def delete_external_services(): LOGGER.info(f"[func] | Request {data}") response = requests. ...