I am pretty new to django, so please excuse me if this is a stupid question.
Django has loads of hooks to aid setting up libraries being used, which is great, but I’m struggling with finding a good way to integrate the requests library (https://requests.readthedocs.io/en/master/).
My situation:
I am making requests to another micro-service, from my django app, using requests.get(...)
, that works fine. I now want to add a default timeout to any requests, I found this blog https://findwork.dev/blog/advanced-usage-python-requests-timeouts-retries-hooks/ that explains how and gives code on how to do it. My problem is the bit that integrates the adapter
. The code there you need to create a session, then add the adapter to it, but that isn’t really the Django way, at least that is what I thought. I thought there might be a way to set this up in my settings.py
file, so that any request I make in future, will have the default timeout, set in the adapter. I have not found anything and am thinking I need to have some wrapper function that our requests use, instead of using request.get(...)
directly, just hoping there is a more django’y way of doing this.
Has anyone done this already and can point me towards some resource(s) to read.
Thanks in advance for any help.
MARK