Neo4j python driver | AttributeError: 'Session' object has no attribute 'execute_read'

984 Views Asked by At

In the Neo4j Python code, I have an issue while query from Neo4j DB, with getting below error:

AttributeError: 'Session' object has no attribute 'execute_read'

I want to convert the results of cypher queries into a JSON format.I am using the neo4j python library to connect the graph DB.

Here is my current code:

cypherQuery="MATCH (n:BusinessApplication) RETURN n"
#Run cypher query
with driver.session() as session:
          results = session.execute_read(lambda tx: tx.run(cypherQuery).data())  
driver.close()
1

There are 1 best solutions below

0
On

The session.execute_read function was introduced in a more recent version of the Neo4j Python driver (5.0) so you may see that error because you're using a previous version of the Neo4j Python driver that does not support that function.

You could upgrade to a more recent version 5.0+ of the Neo4j Python driver to use the execute_read syntax or use the read_transaction function instead:


def get_business_apps(tx):
    results = tx.run("MATCH (n:BusinessApplication) RETURN n")
    for record in results:
        # do something with each record
        print(record['n'])
   

with driver.session() as session:
    session.read_transaction(get_business_apps)

driver.close()