0

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()
Tono Kuriakose
  • 718
  • 6
  • 19
  • Which version of the python driver are you using? – just_another_dotnet_dev Feb 13 '23 at 11:01
  • That's the python version. It's likely you can't see `execute_read` because it was added in version 5.0.0(https://neo4j.com/docs/api/python-driver/current/api.html#neo4j.Session.execute_read). `read_transaction` is available in older driver versions (https://neo4j.com/docs/api/python-driver/current/api.html#neo4j.Session.read_transaction). – just_another_dotnet_dev Feb 13 '23 at 15:03
  • It's neo4j (4.4.10) I have tried by replacing the execute_write with write_transaction execute_read with read_transaction, but it couldn't fix the issue – Tono Kuriakose Feb 13 '23 at 16:56
  • two things: 1. As obvious as this is in the snippet above your code looks a bit oddly indented, it's not that? 2, can you run `print(type.__class__(session).__dict__)` and share the result, it should include what functions are available. – just_another_dotnet_dev Feb 13 '23 at 17:47
  • I just noted (after my 2nd edit) that you reverted my first edit, where I removed the [tag:graphdb] tag. Does this mean that your question *is* about Ontotext’s GraphDB? – Stefan - brox IT-Solutions Mar 15 '23 at 08:13

1 Answers1

2

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

William Lyon
  • 8,371
  • 1
  • 17
  • 22