app.polisplexity.tech/test_neo4j.py
2025-03-02 01:52:37 +00:00

36 lines
1.1 KiB
Python

import logging
from neo4j import GraphDatabase
# 🔹 Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# 🔹 Fallback Credentials (Modify these as needed)
NEO4J_URI = "neo4j://191.101.233.39:7687" # Change to your Neo4j instance
NEO4J_USERNAME = "neo4j"
NEO4J_PASSWORD = "securepassword" # Replace with the real one
def test_neo4j_connection():
"""
Attempts to connect to Neo4j and runs a simple query.
"""
try:
logger.info(f"🔹 Connecting to Neo4j at {NEO4J_URI} with user {NEO4J_USERNAME}")
# 🔹 Establish connection
driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USERNAME, NEO4J_PASSWORD))
# 🔹 Run a basic query
with driver.session() as session:
result = session.run("RETURN 'Neo4j connection successful!' AS message")
message = result.single()["message"]
logger.info(f"{message}")
driver.close()
except Exception as e:
logger.error(f"❌ Failed to connect to Neo4j: {e}")
if __name__ == "__main__":
test_neo4j_connection()