Skip to content

Commit

Permalink
Merge pull request #106 from vkosuri/patch-8
Browse files Browse the repository at this point in the history
backoff_factor the pause between for each retry
  • Loading branch information
bulkan committed Apr 16, 2016
2 parents 15af1dc + 4c99511 commit 551d251
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/RequestsLibrary/RequestsKeywords.py
Expand Up @@ -2,13 +2,13 @@
import json
import sys
from urllib import urlencode
from requests.packages.urllib3.util import Retry

import requests
import robot
from robot.api import logger
from robot.libraries.BuiltIn import BuiltIn


try:
from requests_ntlm import HttpNtlmAuth
except ImportError:
Expand Down Expand Up @@ -42,6 +42,7 @@ def _create_session(
auth,
timeout,
max_retries,
backoff_factor,
proxies,
verify,
debug):
Expand All @@ -56,6 +57,10 @@ def _create_session(
`auth` List of username & password for HTTP Basic Auth
`timeout` Connection timeout
`max_retries` The maximum number of retries each connection should attempt.
`backoff_factor` The pause between for each retry
`proxies` Dictionary that contains proxy urls for HTTP and HTTPS communication
Expand All @@ -71,11 +76,11 @@ def _create_session(
s.auth = auth if auth else s.auth
s.proxies = proxies if proxies else s.proxies

max_retries = self.builtin.convert_to_integer(max_retries)
max_retries = self.builtin.convert_to_integer(max_retries)

if max_retries > 0:
http = requests.adapters.HTTPAdapter(max_retries=max_retries)
https = requests.adapters.HTTPAdapter(max_retries=max_retries)
http = requests.adapters.HTTPAdapter(max_retries=Retry(total=max_retries, backoff_factor=backoff_factor))
https = requests.adapters.HTTPAdapter(max_retries=Retry(total=max_retries, backoff_factor=backoff_factor))

# Replace the session's original adapters
s.mount('http://', http)
Expand Down Expand Up @@ -108,7 +113,7 @@ def _create_session(

def create_session(self, alias, url, headers={}, cookies=None,
auth=None, timeout=None, proxies=None,
verify=False, debug=0, max_retries=3):
verify=False, debug=0, max_retries=3, backoff_factor=0.10):
""" Create Session: create a HTTP session to a server
`url` Base url of the server
Expand All @@ -130,6 +135,8 @@ def create_session(self, alias, url, headers={}, cookies=None,
https://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.set_debuglevel
`max_retries` The maximum number of retries each connection should attempt.
`backoff_factor` The pause between for each retry
"""
auth = requests.auth.HTTPBasicAuth(*auth) if auth else None

Expand All @@ -146,6 +153,7 @@ def create_session(self, alias, url, headers={}, cookies=None,
auth,
timeout,
max_retries,
backoff_factor,
proxies,
verify,
debug)
Expand All @@ -161,7 +169,8 @@ def create_ntlm_session(
proxies=None,
verify=False,
debug=0,
max_retries=3):
max_retries=3,
backoff_factor=0.10):
""" Create Session: create a HTTP session to a server
`url` Base url of the server
Expand All @@ -183,6 +192,8 @@ def create_ntlm_session(
https://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.set_debuglevel
`max_retries` The maximum number of retries each connection should attempt.
`backoff_factor` The pause between for each retry
"""
if not HttpNtlmAuth:
raise AssertionError('Requests NTLM module not loaded')
Expand All @@ -206,13 +217,14 @@ def create_ntlm_session(
ntlm_auth,
timeout,
max_retries,
backoff_factor,
proxies,
verify,
debug)

def create_digest_session(self, alias, url, auth, headers={}, cookies=None,
timeout=None, proxies=None, verify=False,
debug=0, max_retries=3):
debug=0, max_retries=3,backoff_factor=0.10):
""" Create Session: create a HTTP session to a server
`url` Base url of the server
Expand All @@ -234,6 +246,8 @@ def create_digest_session(self, alias, url, auth, headers={}, cookies=None,
https://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.set_debuglevel
`max_retries` The maximum number of retries each connection should attempt.
`backoff_factor` The pause between for each retry
"""
digest_auth = requests.auth.HTTPDigestAuth(*auth) if auth else None

Expand All @@ -245,6 +259,7 @@ def create_digest_session(self, alias, url, auth, headers={}, cookies=None,
digest_auth,
timeout,
max_retries,
backoff_factor,
proxies,
verify,
debug)
Expand Down

0 comments on commit 551d251

Please sign in to comment.