Returns (status_code, body_text).
(url: str)
| 77 | |
| 78 | |
| 79 | def http_get(url: str) -> tuple: |
| 80 | """Returns (status_code, body_text).""" |
| 81 | try: |
| 82 | req = urllib.request.Request(url) |
| 83 | with urllib.request.urlopen(req, timeout=10) as resp: |
| 84 | return resp.status, resp.read().decode() |
| 85 | except urllib.error.HTTPError as e: |
| 86 | return e.code, e.read().decode() if e.fp else "" |
| 87 | except Exception as e: |
| 88 | return 0, str(e) |
| 89 | |
| 90 | |
| 91 | def http_post_json(url: str, data: dict) -> tuple: |