Greetings everyone, I am new at neo4j and seeking your help in solving one issue. I was trying to connect GDS jupyter notebook to local host by following the code suggested in this page "Using Neo4j from Python - Getting Started " however, I am getting error msg of "
AttributeError: 'Session' object has no attribute 'execute_write'" it would be a great help if anyone can solve it for me.
Thanks
Can you share the code that you are using here?
Sure, I was following code from Using Neo4j from Python page:
def __init__(self, uri, user, password):
self.driver = GraphDatabase.driver(uri, auth=(user, password))
def close(self):
self.driver.close()
def print_greeting(self, message):
with self.driver.session() as session:
greeting = session.execute_write(self._create_and_return_greeting, message)
print(greeting)
@staticmethod
def _create_and_return_greeting(tx, message):
result = tx.run("CREATE (a:Greeting) "
"SET a.message = $message "
"RETURN a.message + ', from node ' + id(a)", message=message)
return result.single()[0]
if name == "main":
greeter = HelloWorldExample("bolt://localhost:7687", "neo4j", "mypassword")
greeter.print_greeting("hello, world")
greeter.close()
------ I have got following error:
AttributeError Traceback (most recent call last)
in
1 if name == "main":
2 greeter = HelloWorldExample("bolt://localhost:7687", "neo4j", "23aarisH@")
----> 3 greeter.print_greeting("hello, world")
4 greeter.close()
in print_greeting(self, message)
9 def print_greeting(self, message):
10 with self.driver.session() as session:
---> 11 greeting = session.execute_write(self._create_and_return_greeting, message)
12 print(greeting)
13
AttributeError: 'Session' object has no attribute 'execute_write'
You could try session.write_transaction
instead of session.execute_write
. In driver version 5.0 this method was renamed (the old name still exists but is deprecated).
If this works, you've installed version 4.x of the driver. In that case, I recommend updating to the latest 5.x version, which would also make it so that you don't have to update the code example.
To update to the latest version, you can run pip install -U neo4j
.