Spaces:
Running
Running
File size: 1,714 Bytes
8c9362b |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import requests
import sys
def test_backend_connection():
base_url = "http://127.0.0.1:8000"
print(f"Testing connection to {base_url}...")
try:
# 1. Test Health Endpoint
print("\n1. Pinging Health Endpoint...")
response = requests.get(f"{base_url}/health")
if response.status_code == 200:
print("✅ Backend is reachable and healthy!")
print(f" Response: {response.json()}")
else:
print(f"❌ Backend reachable but returned status {response.status_code}")
print(f" Response: {response.text}")
return
# 2. Test Login Endpoint (Validation Only)
print("\n2. Testing Login Endpoint Reachability...")
# We send garbage data just to see if the server receives it and responds (even with 401/422)
payload = {"identifier": "ping", "password": "pong"}
response = requests.post(f"{base_url}/api/auth/login", json=payload)
print(f" Status Code: {response.status_code}")
if response.status_code in [200, 400, 401, 404, 422]:
print("✅ Login endpoint is reachable (request received by server)")
else:
print("❌ Login endpoint unreachable or unexpected error")
except requests.exceptions.ConnectionError:
print(f"\n❌ CONNECTION FAILED: Could not connect to {base_url}")
print(" - Is the backend server running?")
print(" - Is it running on port 8000?")
print(" - Try: 'python -m uvicorn main:app --reload' in the AIDA directory")
except Exception as e:
print(f"\n❌ AN ERROR OCCURRED: {e}")
if __name__ == "__main__":
test_backend_connection()
|