Skip to main content

Make requests's sessions auto-retry on failure.

Project description

Configures the passed-in requests’ Session to retry on failed requests due to connection errors, timeouts, specific HTTP response codes (5XX by default) and 30X redirections —anything that could fail.

Python 3.6+.

Basic usage:

from retry_requests import retry
my_session = retry()
my_session.get("http://foo.bar")

This get will retry three times in case of error waiting some time between retries. Errors could be:

  • Waiting for the server to start answering for 5 seconds.

  • No access to the server or a dropped connection.

  • An HTTP answer of 500, 502, or 504.

You can change these defaults:

from retry_requests import retry
from requests import Session
my_session = retry(Session(), retries=5, backoff_factor=0.2)
my_session.get('https://foo.bar')

Check the function retry to know more about this configuration.

Note that you have a TSession, a Session with a default timeout, and RSession, a Session with a timeout that always raise_for_status(), for your convenience.

Heavily inspired from Peterbe.com. Thank you!

Installing

Just pip install retry-requests.

Testing

Clone this project and then, at its root directory, run python setup.py test. Note that you need an active Internet connection to run the tests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

retry-requests-1.0.1.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file retry-requests-1.0.1.tar.gz.

File metadata

  • Download URL: retry-requests-1.0.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.8

File hashes

Hashes for retry-requests-1.0.1.tar.gz
Algorithm Hash digest
SHA256 fe1e5daa2bcf23cebb917f93b04ef37ebe2a6b8c5e2e78c9af2723deb1ee8517
MD5 1114013d0278c85ec121999cf2646685
BLAKE2b-256 ee2c843a3b946132f8f1351886b8cd87d2dc8292000f98a9fb1837c3f0e0f259

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page