Really-amin's picture
Upload 325 files
b66240d verified
#!/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)