Skip to content

Commit

Permalink
sleep 1 sec if HTTPError to prevent ip blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed May 17, 2023
1 parent baffcf1 commit 0215a23
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion duckduckgo_search/duckduckgo_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, headers=None, proxies=None, timeout=10):
self._timeout = timeout

def _get_url(self, method, url, **kwargs):
for _ in range(2):
for _ in range(3):
try:
resp = self._session.request(
method, url, timeout=self._timeout, proxies=self._proxies, **kwargs
Expand All @@ -58,6 +58,8 @@ def _get_url(self, method, url, **kwargs):
sleep(5)
resp.raise_for_status()
return resp
except requests.HTTPError:
sleep(1)
except Exception as ex:
logger.debug(f"_get_url() url={url} {type(ex).__name__}")
sleep(0.25)
Expand Down

0 comments on commit 0215a23

Please sign in to comment.