File size: 3,351 Bytes
b66240d |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
#!/usr/bin/env python3
"""
Check if the server is running and accessible
"""
import sys
import socket
import requests
from pathlib import Path
def check_port(host='localhost', port=7860):
"""Check if a port is open"""
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((host, port))
sock.close()
return result == 0
except Exception as e:
print(f"Error checking port: {e}")
return False
def check_endpoint(url):
"""Check if an endpoint is accessible"""
try:
response = requests.get(url, timeout=2)
return response.status_code, response.text[:100]
except requests.exceptions.ConnectionError:
return None, "Connection refused - server not running"
except Exception as e:
return None, str(e)
print("=" * 70)
print("Server Diagnostic Check")
print("=" * 70)
# Check if port is open
print("\n1. Checking if port 7860 is open...")
if check_port('localhost', 7860):
print(" β Port 7860 is open")
else:
print(" β Port 7860 is not open - server is NOT running")
print("\n SOLUTION: Start the server with:")
print(" python main.py")
sys.exit(1)
# Check if it's the correct server
print("\n2. Checking if correct server is running...")
status, text = check_endpoint('http://localhost:7860/health')
if status == 200:
print(" β Health endpoint responds (correct server)")
elif status == 404:
print(" β Health endpoint returns 404")
print(" WARNING: Something is running on port 7860, but it's not the FastAPI server!")
print(" This might be python -m http.server or another static file server.")
print("\n SOLUTION:")
print(" 1. Stop the current server (Ctrl+C in the terminal running it)")
print(" 2. Start the correct server: python main.py")
sys.exit(1)
else:
print(f" β Health endpoint error: {status} - {text}")
sys.exit(1)
# Check API endpoints
print("\n3. Checking API endpoints...")
endpoints = [
'/api/market',
'/api/coins/top?limit=10',
'/api/news/latest?limit=20',
'/api/sentiment',
'/api/providers/config',
]
all_ok = True
for endpoint in endpoints:
status, text = check_endpoint(f'http://localhost:7860{endpoint}')
if status == 200:
print(f" β {endpoint}")
else:
print(f" β {endpoint} - Status: {status}, Error: {text}")
all_ok = False
if not all_ok:
print("\n WARNING: Some endpoints are not working!")
print(" The server is running but routes may not be registered correctly.")
print(" Try restarting the server: python main.py")
# Check WebSocket (can't easily test, but check if route exists)
print("\n4. WebSocket endpoint:")
print(" The /ws endpoint should be available at ws://localhost:7860/ws")
print(" (Cannot test WebSocket from this script)")
print("\n" + "=" * 70)
if all_ok:
print("β Server is running correctly!")
print(" Access the dashboard at: http://localhost:7860/")
print(" API docs at: http://localhost:7860/docs")
else:
print("β Server is running but some endpoints have issues")
print(" Try restarting: python main.py")
print("=" * 70)
|