Files
mtusi2026lab7-fork/student-tests/wait_url.py

20 lines
626 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Ждать HTTP 200 по URL (до 90 с). Используется внутри compose-сети: ops.py in-network."""
import tlsenv # noqa: F401 lab7: HTTPS с проверкой CA стенда
import sys
import time
from urllib.request import urlopen
url = sys.argv[1]
deadline = time.monotonic() + float(sys.argv[2] if len(sys.argv) > 2 else 90)
while time.monotonic() < deadline:
try:
if urlopen(url, timeout=2).status == 200:
print("ready: " + url)
sys.exit(0)
except OSError:
pass
time.sleep(0.5)
print("not ready: " + url)
sys.exit(1)