Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new max_retries param to TwilioHttpClient #507

Merged
merged 2 commits into from
Feb 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion twilio/http/http_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from requests import Request, Session, hooks
from requests.adapters import HTTPAdapter

from twilio.http import HttpClient
from twilio.http.response import Response
Expand All @@ -13,7 +14,7 @@ class TwilioHttpClient(HttpClient):
"""
General purpose HTTP Client for interacting with the Twilio API
"""
def __init__(self, pool_connections=True, request_hooks=None, timeout=None, logger=_logger, proxy=None):
def __init__(self, pool_connections=True, request_hooks=None, timeout=None, logger=_logger, proxy=None, max_retries=None):
"""
Constructor for the TwilioHttpClient

Expand All @@ -23,8 +24,11 @@ def __init__(self, pool_connections=True, request_hooks=None, timeout=None, logg
Timeout should never be zero (0) or less.
:param logger
:param dict proxy: Http proxy for the requests session
:param int max_retries: Maximum number of retries each request should attempt
"""
self.session = Session() if pool_connections else None
if self.session and max_retries is not None:
self.session.mount('https://', HTTPAdapter(max_retries=max_retries))
self.last_request = None
self.last_response = None
self.logger = logger
Expand Down