(url: str, *, headers: dict[str, str] | None = None, timeout: float = 5.0)
| 8 | |
| 9 | |
| 10 | def http_get(url: str, *, headers: dict[str, str] | None = None, timeout: float = 5.0) -> tuple[int, bytes]: |
| 11 | req = Request(url, headers=headers or {}, method="GET") |
| 12 | try: |
| 13 | with urlopen(req, timeout=timeout) as resp: |
| 14 | return int(getattr(resp, "status", 200)), resp.read() |
| 15 | except HTTPError as e: |
| 16 | body = b"" |
| 17 | try: |
| 18 | body = e.read() |
| 19 | except Exception: |
| 20 | pass |
| 21 | return int(getattr(e, "code", 0) or 0), body |
| 22 | |
| 23 | |
| 24 | def http_post( |