| 546 | |
| 547 | def _create_http_session() -> requests.Session: |
| 548 | session = requests.Session() |
| 549 | session.trust_env = True |
| 550 | |
| 551 | if Retry is not None and HTTP_RETRY_TOTAL > 0: |
| 552 | retry = Retry( |
| 553 | total=HTTP_RETRY_TOTAL, |
| 554 | connect=HTTP_RETRY_TOTAL, |
| 555 | read=HTTP_RETRY_TOTAL, |
| 556 | status=HTTP_RETRY_TOTAL, |
| 557 | backoff_factor=HTTP_RETRY_BACKOFF, |
| 558 | allowed_methods=frozenset({"GET", "HEAD"}), |
| 559 | status_forcelist=(408, 425, 429, 500, 502, 503, 504, 520, 521, 522, 524), |
| 560 | respect_retry_after_header=True, |
| 561 | raise_on_status=False, |
| 562 | ) |
| 563 | adapter = HTTPAdapter(max_retries=retry) |
| 564 | session.mount("http://", adapter) |
| 565 | session.mount("https://", adapter) |
| 566 | |
| 567 | return session |
| 568 | |
| 569 | |
| 570 | def _http_get( |
| 571 | url: str, |