Within my code, all requests have a timeout period. And for each request, I have to handle the Timeout exception. Is there any way to attach a global Timeout exception handler with the requests?
try:
request = requests.post(url=url1, data=data, headers=headers, timeout=Config.REQUEST_TIMEOUT)
except Timeout:
raise ServiceUnavailable()
try:
request = requests.post(url=url2, data=data, headers=headers, timeout=Config.REQUEST_TIMEOUT)
except Timeout:
raise ServiceUnavailable()
Like above I every time I have to handle timeout and raise service unavailable. I want something generic, whenever timeout occurs it will raise service unavailable.