From 75b48155c2ffb17b6831a391bfc0a5f0e74baa98 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Thu, 15 Aug 2019 18:02:50 -0700 Subject: [PATCH] Allow UnixAdapter to accept max_retries parameter e.g.: ```python from requests.packages.urllib3.util.retry import Retry import requests_unixsocket sess = requests_unixsocket.Session() HTTP_REQUEST_RETRIES = 3 HTTP_RETRY_BACKOFF_FACTOR = 0.3 HTTP_RETRY_FORCELIST = (404, 500, 502, 504) retry = Retry(total=HTTP_REQUEST_RETRIES, read=HTTP_REQUEST_RETRIES, connect=HTTP_REQUEST_RETRIES, backoff_factor=HTTP_RETRY_BACKOFF_FACTOR, status_forcelist=HTTP_RETRY_FORCELIST) adapter = requests_unixsocket.UnixAdapter(max_retries=retry) sess.mount('http+unix://', adapter) print(sess.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/this-does-not-exist')) ``` Fixes: GH-37 --- requests_unixsocket/adapters.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/requests_unixsocket/adapters.py b/requests_unixsocket/adapters.py index a2c1564..83e1400 100644 --- a/requests_unixsocket/adapters.py +++ b/requests_unixsocket/adapters.py @@ -56,13 +56,12 @@ def _new_conn(self): class UnixAdapter(HTTPAdapter): - def __init__(self, timeout=60, pool_connections=25): - super(UnixAdapter, self).__init__() + def __init__(self, timeout=60, pool_connections=25, *args, **kwargs): + super(UnixAdapter, self).__init__(*args, **kwargs) self.timeout = timeout self.pools = urllib3._collections.RecentlyUsedContainer( pool_connections, dispose_func=lambda p: p.close() ) - super(UnixAdapter, self).__init__() def get_connection(self, url, proxies=None): proxies = proxies or {}