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

Add retry mechanism to HTTP requests #26

Open
michaelwood opened this issue Oct 5, 2021 · 3 comments
Open

Add retry mechanism to HTTP requests #26

michaelwood opened this issue Oct 5, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@michaelwood
Copy link
Member

We've seen a few cases where an HTTP request fail and then subsequently work. Retrying a request is fairly standard due to the nature of the internet so it would be a useful feature to add to the datagetter.

@michaelwood michaelwood added the enhancement New feature or request label Oct 5, 2021
@michaelwood
Copy link
Member Author

@michaelwood
Copy link
Member Author

example code:

import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

def get_data(url):
    retry_strategy = Retry(
        total=3,
        backoff_factor=1,
        status_forcelist=[429, 500, 502, 503, 504],
        method_whitelist=["HEAD", "GET", "OPTIONS"]
    )
    adapter = HTTPAdapter(max_retries=retry_strategy)
    session = requests.Session()
    session.mount("http://", adapter)
    session.mount("https://", adapter)

    response = session.get(url)

    if response.status_code != 200:
        response.raise_for_status()

    return response.content

@michaelwood
Copy link
Member Author

include all tries including those to the registry when we may get invalid json due to connection problem with SF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant