Spaces:
Running
Running
File size: 903 Bytes
6ab2222 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import os
import requests
import sys
import json
API_BASE = os.getenv("API_BASE", "http://localhost:8080")
MESSAGE = os.getenv("TEST_MESSAGE", "Please verify your account at http://example.com/login")
TIMEOUT = int(os.getenv("TEST_TIMEOUT", "10"))
endpoints = ["/analyze", "/analyze/or1", "/analyze/or2"]
print(f"Testing API at {API_BASE} with message: {MESSAGE}\n")
for ep in endpoints:
url = API_BASE.rstrip("/") + ep
payload = {"message": MESSAGE}
try:
resp = requests.post(url, json=payload, timeout=TIMEOUT)
try:
body = resp.json()
except Exception:
body = resp.text
print(f"Endpoint: {ep} -> Status: {resp.status_code}")
print(json.dumps(body, indent=2, ensure_ascii=False))
except requests.exceptions.RequestException as e:
print(f"Endpoint: {ep} -> Request failed: {e}")
print("---")
print("Done.")
|