Skip to content

Commit

Permalink
feat: retry on urllib3 MaxRetryError (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Jul 21, 2022
1 parent 4f86f54 commit d6e566e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions eth_retry/conditional_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
class DummyException(Exception):
pass

# eth-brownie
try:
from sqlite3 import OperationalError
except ModuleNotFoundError:
OperationalError = DummyException

# web3py
try:
from requests.exceptions import HTTPError, ReadTimeout
except ModuleNotFoundError:
HTTPError, ReadTimeout = DummyException, DummyException

# aiohttp
try:
from urllib3.exceptions import MaxRetryError
except ModuleNotFoundError:
MaxRetryError = DummyException
6 changes: 4 additions & 2 deletions eth_retry/eth_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import requests

from eth_retry.conditional_imports import (HTTPError, # type: ignore
OperationalError, ReadTimeout)
MaxRetryError, OperationalError,
ReadTimeout)

logger = logging.getLogger('eth_retry')

Expand Down Expand Up @@ -103,7 +104,8 @@ def should_retry(e: Exception, failures: int) -> bool:
ConnectionError,
requests.exceptions.ConnectionError,
HTTPError,
ReadTimeout
ReadTimeout,
MaxRetryError,
]
if any(isinstance(e, E) for E in general_exceptions) and 'Too Large' not in str(e) and '404' not in str(e):
return True
Expand Down

0 comments on commit d6e566e

Please sign in to comment.