msabramo / requests-unixsocket

Use requests to talk HTTP via a UNIX domain socket
Apache License 2.0
207 stars 29 forks source link

Allow UnixAdapter to accept max_retries parameter #42

Closed msabramo closed 5 years ago

msabramo commented 5 years ago

e.g.:

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

Cc: @fantamiracle, @keith-bennett-gbg

keith-bennett-gbg commented 5 years ago

Thank you!

msabramo commented 2 years ago

(finally) released in https://pypi.org/project/requests-unixsocket/0.3.0/