# I'm using the neo4j Python driver to create and retrieve Person nodes in a Neo4j database. The nodes are successfully created and visible in the Neo4j browser, but my Python script returns zero records when querying these nodes

**URL:** <https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177>\
**Category:** Python\
**Created:** [August 11, 2024, 5:03pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177 "2024-08-11T17:03:11Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![aish](https://avatars.discourse-cdn.com/v4/letter/a/3d9bf3/32.png) [@aish](https://community.neo4j.com/u/aish)\
**Post date:** [August 11, 2024, 5:03pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/1 "2024-08-11T17:03:11Z")

</div>

from neo4j import GraphDatabase

**# Connect to the Neo4j database using Bolt protocol**  
driver = GraphDatabase.driver("neo4j://localhost:7687", auth=("test\_user", "test\_password"))

def create\_person(tx, name):  
result = tx.run("CREATE (:Person {name: $name})", name=name)  
summary = result.consume()  
print(f"Created node: {name}, {summary.counters.nodes\_created} nodes created")

def get\_persons(tx):  
query = """  
MATCH (p:Person)  
RETURN p.name AS name  
"""  
result = tx.run(query)  
return [record["name"] for record in result]

with driver.session() as session:  
session.execute\_write(create\_person, "Alice")  
session.execute\_write(create\_person, "Bob")  
session.execute\_write(create\_person, "Charlie")

with driver.session() as session:  
persons = session.execute\_read(get\_persons)  
if not persons:  
print("No Person nodes found.")  
else:  
print(f"Found {len(persons)} Person nodes:")  
for person in persons:  
print(person)

driver.close()

**output:**

Created node: Alice, 1 nodes created  
Created node: Bob, 1 nodes created  
Created node: Charlie, 1 nodes created  
The query `MATCH (p:Person) RETURN p.name AS name` returned 0 records in 0 ms.

Additional Information:

- Neo4j Version: 5.22.0 Enterprise edition
- Python Driver Version: 5.19.0
- The `Person` nodes are visible in the Neo4j browser when querying `MATCH (n:Person) RETURN n LIMIT 25`.  
 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/1/8/18d73bffd86684c173f69125f627dce03ea3b925.png)

**Question:**

Why is my Python script returning zero records even though the nodes are successfully created and visible in the Neo4j browser? Are there any permissions or session management issues that I might be overlooking?

---

<div class="post-metadata">

**Author:** ![rouven\_bauer](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rouven_bauer/32/16547_2.png) [@rouven\_bauer](https://community.neo4j.com/u/rouven_bauer)\
**Post date:** [August 12, 2024, 6:14am UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/2 "2024-08-12T06:14:40Z")

</div>

Hi 👋

Are you running against a cluster? In such case, this could be a problem or reading stale writes. You'd need to use bookmarks or a bookmark manager to causally chain your sessions. Have a look at this documentation: [Coordinate parallel transactions - Neo4j Python Driver Manual](https://neo4j.com/docs/python-manual/current/bookmarks/).

---

<div class="post-metadata">

**Author:** ![gerrit.meier](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/gerrit.meier/32/27374_2.png) [@gerrit.meier](https://community.neo4j.com/u/gerrit.meier)\
**Post date:** [August 15, 2024, 1:33pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/3 "2024-08-15T13:33:35Z")

</div>

For you minimal example you could also just work in the same `session`.  
It should handle the read-your-own-writes scenario.  
Of course this is not a solution if the write and read code is separated and you are using multiple sessions. Then you have to either live with the eventual consistency of the cluster or explicitly use the bookmarks, as Rouven suggested.

```python
def create_person(tx, name):
    result = tx.run("CREATE (:Person {name: $name})", name=name)
    summary = result.consume()
    print(f"Created node: {name}, {summary.counters.nodes_created} nodes created")

def get_persons(tx):
    query = """
    MATCH (p:Person)
    RETURN p.name AS name
    """
    result = tx.run(query)
    return [record["name"] for record in result]

with GraphDatabase.driver(
    "neo4j://localhost:7687",
    auth=("test_user", "test_password"),
) as driver:
    with driver.session(
        # specify the database name is possible for better performance
        databse="neo4j",
    ) as session:
        session.execute_write(create_person, "Alice")
        session.execute_write(create_person, "Bob")
        session.execute_write(create_person, "Charlie")
        persons = session.execute_read(get_persons)
        if not persons:
            print("No Person nodes found.")
        else:
            print(f"Found {len(persons)} Person nodes:")
        for person in persons:
            print(person)

```

---

<div class="post-metadata">

**Author:** ![larrykone](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/larrykone/32/32614_2.png) [@larrykone](https://community.neo4j.com/u/larrykone)\
**Post date:** [September 9, 2024, 2:57pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/4 "2024-09-09T14:57:59Z")

</div>

Hi Gerrit - I am creating an app using python and flask and look to use neo4j rather than SQL. I am grateful for any help you can give me to get started. This appears to be the first time I have not had a connection error.

I am an absolute newbie at using the python drive to run the simplest possible code that connects with a neo4j database. I used your code (admittedly not the absolute simplest like a Hello World! function in python) along with driver.close() at the end.

Got error:

neo4j.exceptions.ConfigurationError: Unexpected config keys: databse

Traceback:

(.venv) larryeisenberg@Mac Neo4j Learn % python3 start.py  
Traceback (most recent call last):  
File "/Users/larryeisenberg/PycharmProjects/Neo4j Learn/start.py", line 22, in   
with driver.session(  
^^^^^^^^^^^^^^^  
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/\_sync/driver.py", line 577, in session  
session\_config = self.\_read\_session\_config(config)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/\_sync/driver.py", line 585, in \_read\_session\_config  
session\_config = SessionConfig(self.\_default\_workspace\_config,  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/\_conf.py", line 325, in **init**  
self.\_\_update(arg)  
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/\_conf.py", line 317, in \_\_update  
raise ConfigurationError("Unexpected config keys: "  
neo4j.exceptions.ConfigurationError: Unexpected config keys: databse  
(.venv) larryeisenberg@Mac Neo4j Learn %

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [September 9, 2024, 3:28pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/5 "2024-09-09T15:28:10Z")

</div>

@larrykone

> [@larrykone](#):
>
> Unexpected config keys: databse

not sure where in your python script but looks like a typo. shouldnt `databse` be `database`. If you search your python for `databse` does it find any matches.

---

<div class="post-metadata">

**Author:** ![larrykone](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/larrykone/32/32614_2.png) [@larrykone](https://community.neo4j.com/u/larrykone)\
**Post date:** [September 9, 2024, 3:36pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/6 "2024-09-09T15:36:51Z")

</div>

Thank you Dana. I corrected the typo, but still have an error: (Unable to retrieve routing information)

Traceback:

(.venv) larryeisenberg@Mac Neo4j Learn % python3 start.py  
Unable to retrieve routing information  
Transaction failed and will be retried in 0.9282055267891798s (Unable to retrieve routing information)  
Unable to retrieve routing information  
Transaction failed and will be retried in 2.0540795382718255s (Unable to retrieve routing information)  
Unable to retrieve routing information  
Transaction failed and will be retried in 3.5454048363608326s (Unable to retrieve routing information)  
Unable to retrieve routing information  
Transaction failed and will be retried in 8.365545390250297s (Unable to retrieve routing information)  
^CTraceback (most recent call last):  
File "/Users/larryeisenberg/PycharmProjects/Neo4j Learn/start.py", line 26, in   
session.execute\_write(create\_person, "Alice")  
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/\_sync/work/session.py", line 757, in execute\_write  
return self.\_run\_transaction(  
^^^^^^^^^^^^^^^^^^^^^^  
File "/Users/larryeisenberg/PycharmProjects/Neo4jLearn/.venv/lib/python3.11/site-packages/neo4j/\_sync/work/session.py", line 582, in \_run\_transaction  
sleep(delay)  
KeyboardInterrupt

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [September 9, 2024, 3:42pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/7 "2024-09-09T15:42:42Z")

</div>

@larrykone

'Unable to retrieve routing information' would suggest your Python script can not connect to Neo4j. When connecting via the Neo4j Browser, what is the value for the `Connect URL` on the authentication page? Is your username/password `test_user` and `test_password` as described in @gerrit.meier response and 5 lines above the typo of 'databse`

---

<div class="post-metadata">

**Author:** ![larrykone](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/larrykone/32/32614_2.png) [@larrykone](https://community.neo4j.com/u/larrykone)\
**Post date:** [September 9, 2024, 5:04pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/8 "2024-09-09T17:04:03Z")

</div>

Thank you for getting back to me Dana. Much appreciated!

I think this part of the code answers your questions:

with GraphDatabase.driver(  
"neo4j://localhost:7687",  
auth=("test\_user", "test\_password"),  
) as driver:  
with driver.session(  
# specify the database name is possible for better performance  
database="neo4j",

---

<div class="post-metadata">

**Author:** ![dana\_canzano](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dana_canzano/32/27392_2.png) [@dana\_canzano](https://community.neo4j.com/u/dana_canzano)\
**Post date:** [September 9, 2024, 6:20pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/9 "2024-09-09T18:20:15Z")

</div>

@larrykone

your code snippet of

```auto
with GraphDatabase.driver(
"neo4j://localhost:7687",
auth=("test_user", "test_password"),
) as driver:
with driver.session(
# specify the database name is possible for better performance
database="neo4j",

```

indicates  
line 2: connect with a protocal named `neo4j://` and to a Neo4j database running on `localhost` and listening on port `7687`. `localhost` is effectively the same instance/OS where the script is run from

line3: connect with authentication defined as user='test\_user' and password='test\_password`

line 7: connect to a database which is named `neo4j`

but how does this compare to the same values as entered when connecting via the Neo4j Browser, which you claim you have success with and

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/d/2/d2ec2c6b0baffff788c3dcf0d3015bff95a86857.png)

---

<div class="post-metadata">

**Author:** ![larrykone](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/larrykone/32/32614_2.png) [@larrykone](https://community.neo4j.com/u/larrykone)\
**Post date:** [September 10, 2024, 4:57pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/10 "2024-09-10T16:57:18Z")

</div>

Hi Dana - Maybe I am wasting your time and mine, but before I just go with SQLAlchemy and SQLight, I give it another try and if it does not result in a good connection I won't waste the time anymore of anyone at Neo4j.

I gather you say I have the wrong values. So what are the correct values? I am rather amazed how difficult it is to get started coding with neo4j and python to create a web app. It is amazingly easier to use python, flask and SQL Alchemy. I just don't get it. Neo4j has been around for over a decade and it's this difficult to take the first step? I wonder how many other developers have decided to just use SQL rather than fail over and over again and what should be easy and quick if compared to using SQL with python on a local server. I just don't get it.

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [September 11, 2024, 1:09am UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/11 "2024-09-11T01:09:54Z")

</div>

I have been using Java driver for a few years and SDN as well. I find it easy to connect and use. I also find cypher a lot more fun and enjoyable than SQL, which have been using for a while. If you need a graph database to efficiently model your data, such as network or hierarchical data, etc, you are not going easily, if at all, do the same in a sql database.

They are both tools that have their place, and they should not be considered interchangeable.

Are you connecting to a local database or remote database in your browser?

---

<div class="post-metadata">

**Author:** ![larrykone](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/larrykone/32/32614_2.png) [@larrykone](https://community.neo4j.com/u/larrykone)\
**Post date:** [September 12, 2024, 10:03pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/12 "2024-09-12T22:03:47Z")

</div>

Hi Gary,

I am trying to this all locally as I would using Flask, SQLAlchemy and Python. I am open to any guidance or suggestions that you might have. Thanks,

Larry

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [September 13, 2024, 12:24pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/13 "2024-09-13T12:24:08Z")

</div>

Can you post the full python code related to neo4j

---

<div class="post-metadata">

**Author:** ![larrykone](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/larrykone/32/32614_2.png) [@larrykone](https://community.neo4j.com/u/larrykone)\
**Post date:** [September 15, 2024, 3:07am UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/14 "2024-09-15T03:07:03Z")

</div>

Hi Gary,

Suggestion: show me code using python and neo4j locally that creates a connection, creates a node and then verifies that the node was created? Perhaps that is easier than you correcting bad code?

Larry

---

<div class="post-metadata">

**Author:** ![larrykone](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/larrykone/32/32614_2.png) [@larrykone](https://community.neo4j.com/u/larrykone)\
**Post date:** [September 25, 2024, 7:10pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/15 "2024-09-25T19:10:39Z")

</div>

How do I get from this pic to the one where yo want me to check “Connect to Neo4j”?

(Attachment Neo4jBrowser whre from here.pdf is missing)

---

<div class="post-metadata">

**Author:** ![larrykone](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/larrykone/32/32614_2.png) [@larrykone](https://community.neo4j.com/u/larrykone)\
**Post date:** [September 25, 2024, 7:16pm UTC](https://community.neo4j.com/t/im-using-the-neo4j-python-driver-to-create-and-retrieve-person-nodes-in-a-neo4j-database-the-nodes-are-successfully-created-and-visible-in-the-neo4j-browser-but-my-python-script-returns-zero-records-when-querying-these-nodes/69177/16 "2024-09-25T19:16:15Z")

</div>

Here is the log if that helps. I think I have an authorization error.

(Attachment neo4j.log is missing)
