Python, Neo4j, Local Data Base, Pycharm or Terminal

I tried running:

import neo4j
from collections import defaultdict
from neo4j import GraphDatabase

driver = GraphDatabase.driver(
"bolt://localhost:127.0.0.1:7687",
auth=("neo4j", "")
)

with driver.session() as s:
result = s.run("MATCH (n) RETURN n")

Got error:

raise ValueError("Cannot resolve address {}".format(address))
ValueError: Cannot resolve address localhost:127.0.0.1:7687

this is on a mac with python 3.11.4

localhost:7687
or
127.0.0.1:7687

Those are the correct way to specify a host:port

Thanks John, Here is where I am now,

Code:

from neo4j import GraphDatabase

uri = "neo4j://localhost:7687"
username = "neo4j"
password = "larry1234"
driver = GraphDatabase.driver(uri, auth=("neo4j", "larry1234"))

def add_node(tx, name):
tx.run("CREATE (n:Person {name: $name})", name=name)

with driver.session() as session:
session.write_transaction(add_node, "Alice")

def get_person(tx, name):
result = tx.run("MATCH (n:Person {name: $name}) RETURN n.name AS name", name=name)
return [record["name"] for record in result]

with driver.session() as session:
names = session.read_transaction(get_person, "Alice")
print(names)

Traceback:

(.venv) larryeisenberg@Mac Neo4j Learn % python3 start.py
/Users/larryeisenberg/PycharmProjects/Neo4j Learn/start.py:14: DeprecationWarning: write_transaction has been renamed to execute_write
session.write_transaction(add_node, "Alice")
Unable to retrieve routing information
Transaction failed and will be retried in 1.1749627964073484s (Unable to retrieve routing information)
Unable to retrieve routing information
Transaction failed and will be retried in 2.3681576328980216s (Unable to retrieve routing information)
Unable to retrieve routing information
Transaction failed and will be retried in 3.371229488928044s (Unable to retrieve routing information)
^CTraceback (most recent call last):
File "/Users/larryeisenberg/PycharmProjects/Neo4j Learn/start.py", line 14, in
session.write_transaction(add_node, "Alice")
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/_meta.py", line 224, in inner
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/_sync/work/session.py", line 799, in write_transaction
return self._run_transaction(
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/_sync/work/session.py", line 584, in _run_transaction
sleep(delay)
KeyboardInterrupt

I very much appreciate your help.

I also tried:

from neo4j import GraphDatabase

Create a new Driver instance

with GraphDatabase.driver(
"neo4j://localhost:7687",
auth=("neo4j", "neo")
) as driver:
driver.verify_connectivity()

traceback:

(.venv) larryeisenberg@Mac Neo4j Learn % python3 start.py
Unable to retrieve routing information
Traceback (most recent call last):
File "/Users/larryeisenberg/PycharmProjects/Neo4j Learn/start.py", line 29, in
driver.verify_connectivity()
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/_sync/driver.py", line 1067, in verify_connectivity
self._get_server_info(session_config)
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/_sync/driver.py", line 1281, in _get_server_info
return session._get_server_info()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/_sync/work/session.py", line 172, in _get_server_info
self._connect(READ_ACCESS, liveness_check_timeout=0)
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/_sync/work/session.py", line 130, in _connect
super()._connect(
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/_sync/work/workspace.py", line 165, in _connect
self._pool.update_routing_table(
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/_sync/io/_pool.py", line 802, in update_routing_table
raise ServiceUnavailable("Unable to retrieve routing information")
neo4j.exceptions.ServiceUnavailable: Unable to retrieve routing information
(.venv) larryeisenberg@Mac Neo4j Learn %