J2897

API 'ping' test

Jun 16th, 2026 (edited)
14,100
0
Never
12
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. """
  2. API Checker
  3.  
  4. Sends a request to a free Ping endpoint and displays
  5. the HTTP status code and ping result.
  6. """
  7.  
  8. import json
  9.  
  10. import requests
  11.  
  12. URL = "https://api.formatdock.com/v1/free/ping"
  13.  
  14.  
  15. def main() -> None:
  16.     try:
  17.         response = requests.get(URL, timeout=10)
  18.         response.raise_for_status()
  19.  
  20.         data = response.json()
  21.  
  22.         print(f"Status: {response.status_code}")
  23.         print(f"Result: {data['result']}")
  24.         print("Response:")
  25.         print(json.dumps(data, indent=2, sort_keys=True))
  26.     except requests.RequestException as exc:
  27.         print(f"Request failed: {exc}")
  28.     except (TypeError, ValueError, KeyError) as exc:
  29.         print(f"Unexpected response: {exc}")
  30.  
  31.  
  32. if __name__ == "__main__":
  33.     main()
Advertisement