Closed fantamiracle closed 5 years ago
I would prefer to pass the retry object to the requests_unixsocket.Session
constructor. But we can install the retry object into the UnixAdapter
instead of mounting a new custom adapter.
import requests_unixsocket
from requests.packages.urllib3.util.retry import Retry
def TimeoutRetry(session = None):
# Set up your own Retry object. This one fits my scenario.
# I'm connecting to a forward-proxy via UNIX socket. The forward-proxy runs
# on a different user, validates and logs requests, and then forwards the
# request to another server. Sometimes that server is paged-out and will
# cause a 504 gateway timeout. In that case, I want to just retry the
# request. My specific back-end server uses POST inappropriately so I set
# method_whitelist to False to allow all methods to retry.
retries = Retry(
total=5,
method_whitelist=False,
status_forcelist=[504],
backoff_factor=1
)
session = session or requests_unixsocket.Session()
adapter = session.get_adapter(requests_unixsocket.DEFAULT_SCHEME)
adapter.max_retries = retries
return session
Have a look at https://github.com/msabramo/requests-unixsocket/pull/42 and let me know if that works for you.
@msabramo Hi Marc, I came here to report exactly the same problem and was happy to see the fix I had in mind merged by https://github.com/msabramo/requests-unixsocket/pull/42/files . Could you release a new version with the fix? https://files.pythonhosted.org/packages/4d/ce/78b651fe0adbd4227578fa432d1bde03b4f4945a70c81e252a2b6a2d895f/requests-unixsocket-0.2.0.tar.gz doesn't seem to contain kwargs in UnixAdapter.__init__
. Thank you!
I am wondering if there is a way to mount retry adapter to unix_socket session.
Here is the code snippet:
and here is there error:
Any help is appreciated!