diff --git a/marathon/client.py b/marathon/client.py index 37b1497..6300248 100644 --- a/marathon/client.py +++ b/marathon/client.py @@ -32,6 +32,7 @@ def __init__(self, servers, username=None, password=None, timeout=10): :param str password: Basic auth password :param int timeout: Timeout (in seconds) for requests to Marathon """ + self.session = requests.Session() self.servers = servers if isinstance(servers, list) else [servers] self.auth = (username, password) if username and password else None self.timeout = timeout @@ -59,8 +60,9 @@ def _do_request(self, method, path, params=None, data=None): server = servers.pop(0) url = ''.join([server.rstrip('/'), path]) try: - response = requests.request(method, url, params=params, data=data, headers=headers, - auth=self.auth, timeout=self.timeout) + response = self.session.request( + method, url, params=params, data=data, headers=headers, + auth=self.auth, timeout=self.timeout) marathon.log.info('Got response from %s', server) except requests.exceptions.RequestException as e: marathon.log.error(