MCPcopy Create free account
hub / github.com/RASAAS/docmcp-knowledge / _request_with_retry

Function _request_with_retry

scripts/fetch_nifdc_standards.py:83–101  ·  view source on GitHub ↗
(
    session: requests.Session,
    method: str,
    url: str,
    *,
    params=None,
    data=None,
    timeout: int = DEFAULT_TIMEOUT,
)

Source from the content-addressed store, hash-verified

81
82
83def _request_with_retry(
84 session: requests.Session,
85 method: str,
86 url: str,
87 *,
88 params=None,
89 data=None,
90 timeout: int = DEFAULT_TIMEOUT,
91) -> Optional[requests.Response]:
92 for attempt in range(1, MAX_RETRIES + 1):
93 try:
94 r = session.request(method, url, params=params, data=data, timeout=timeout)
95 if r.status_code >= 500:
96 raise requests.HTTPError(f"{r.status_code}")
97 return r
98 except (requests.RequestException, requests.HTTPError) as exc:
99 print(f"[warn] {method} {url} attempt {attempt}/{MAX_RETRIES}: {exc}", flush=True)
100 time.sleep(min(2 ** attempt, 10))
101 return None
102
103
104def _cell_text(td) -> str:

Callers 1

fetch_allFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected