Cannot connect to Neo4j in Python to push data

I am going slightly crazy trying to understand why I can't push data to my Neo4j database using CYPHER in Python.

I am running basic testing code just to see if I can push data. Here is my testing code:

import logging
from neo4j import GraphDatabase

# Set up logging
logging.basicConfig(level=logging.DEBUG)  # Change the level to ERROR, WARNING, INFO, or DEBUG as needed
log = logging.getLogger("neo4j")

class Neo4jService:
    def __init__(self, uri, user, password):
        self._driver = GraphDatabase.driver(uri, auth=(user, password))
        
    def close(self):
        log.debug("Closing driver.")
        self._driver.close()
        
    def run_queries(self, queries):
        log.debug("Running queries.")
        with self._driver.session() as session:
            for query in queries:
                log.debug(f"Executing query: {query}")
                session.run(query)

try:
    # Initialize the Neo4j service
    URI = "neo4j+s://838f9df7.databases.neo4j.io"
    AUTH = ("neo4j", "my_password")

    log.info("Initializing driver.")
    with GraphDatabase.driver(URI, auth=AUTH) as driver:
        log.info("Verifying connectivity.")
        driver.verify_connectivity()

    summary = driver.execute_query(
        "MERGE (:Person {name: $name})",
        name="Alice",
        database_="neo4j",
    ).summary

    log.info(f"Created {summary.counters.nodes_created} nodes in {summary.result_available_after} ms.")

except Exception as e:
    log.error("An error occurred:", exc_info=True)

Whatever I seem to do, I get an error like this:

neo4j.exceptions.ServiceUnavailable: Unable to retrieve routing information

I have tried manually telling the Neo4j to trust the certificate by saving the certificate as a file and including a trust setting in my code. But this didn't work. I have tried swithcing from neo4j+s to bolt or just neo4j. I have updated neo4j and python. I feel like I have been debugging for about two days. Whatever I do, nothing happens in my Neo4j database. Help appreciated!



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation