AI-Life-Coach-Streamlit / test_network_connectivity.py
rdune71's picture
Add comprehensive Redis connection debugging and network testing scripts
6c0af85
import socket
import ssl
def test_tcp_connection(host, port):
"""Test basic TCP connection to host:port"""
print(f"Testing TCP connection to {host}:{port}...")
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(10)
result = sock.connect_ex((host, port))
sock.close()
if result == 0:
print("βœ… TCP connection successful")
return True
else:
print(f"❌ TCP connection failed with error code: {result}")
return False
except Exception as e:
print(f"❌ TCP connection failed: {e}")
return False
def test_ssl_connection(host, port):
"""Test SSL connection to host:port"""
print(f"Testing SSL connection to {host}:{port}...")
try:
context = ssl.create_default_context()
with socket.create_connection((host, port), timeout=10) as sock:
with context.wrap_socket(sock, server_hostname=host) as ssock:
print(f"βœ… SSL connection successful")
print(f"SSL version: {ssock.version()}")
return True
except Exception as e:
print(f"❌ SSL connection failed: {e}")
return False
if __name__ == "__main__":
host = 'redis-16717.c85.us-east-1-2.ec2.redns.redis-cloud.com'
port = 16717
print("=== Network Connectivity Tests ===")
tcp_result = test_tcp_connection(host, port)
print()
ssl_result = test_ssl_connection(host, port)
print("\n=== Summary ===")
if tcp_result and ssl_result:
print("βœ… All network tests passed")
elif tcp_result:
print("⚠️ TCP connection works but SSL failed")
else:
print("❌ Network connectivity issues detected")