Can a python requests.Session break? If yes, what should I do?

51 Views Asked by At

I have python workers. They use a similar code than the one below:

import requests


class Requester:

    def __init__(self):
        self.session = requests.Session()

    def get(self):
        return self.session.get("https://...", params={"a": "b"})

My goal is to save ~50ms latency with the help of a session to perform multiple independant calls.

I have no authentication nor cookies involved.

The question is: should I fear the session to "break" and my subsequent get calls to fail? Will the requests library try to open a new one under the hood if such a situation happens?

If the session might break, how should I handle such cases? With a try/catch block and try to replace the old one with a new one?

0

There are 0 best solutions below