|
|
|
|
|
"""
|
|
|
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)
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|