# Cannot connect to Community Noe4j 2025 09 from Python on same machine

**URL:** <https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719>\
**Category:** Drivers & Stacks\
**Created:** [October 17, 2025, 8:24pm UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719 "2025-10-17T20:24:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![curtjef1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/curtjef1/32/36076_2.png) [@curtjef1](https://community.neo4j.com/u/curtjef1)\
**Post date:** [October 17, 2025, 8:24pm UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/1 "2025-10-17T20:24:48Z")

</div>

I have the latest Community version of Neo4j 2025 09 and cannot connect to it from a python script - on the same machine. Is there a problem with this version?

python code:

```auto

```

from neo4j import GraphDatabase

class SampleExample:

...

if \ __name_\_ == "\__ main_\_":

```
username = "neo4j"             
password = "..........."         

try:
    greeter = SampleExample(uri, username, password)
    greeter.print_greeting("Welcome to neo4j")
    greeter.close()
except Exception as e:
    print(f"Error: {e}")
    print("Please ensure Neo4j is running and the connection details are correct")

```

.....

Error Msg 1:

```auto
Failed to connect to Neo4j: Couldn't connect to 0.0.0.0:7687 (resolved to ('0.0.0.0:7687',)):
Failed to establish connection to ResolvedIPv4Address(('0.0.0.0', 7687)) (reason [Errno 111] Connection refused

```

```auto

```

```auto
Error Msg 2(occurs when I juggle the uri string (e.g., localhost:7687 or 0.0.0.0:7687, etc.):

```

```auto

```

```auto
Connection error: Couldn't connect to localhost:7687 (resolved to ('127.0.0.1:7687',)):
Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused

```

```auto

```

```auto
Please help. I downloaded neo4j specifically to connect with python.

```

```auto
Thanks

```

```auto

```

```auto
Curtis

```

---

<div class="post-metadata">

**Author:** ![jon.giffard1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jon.giffard1/32/34147_2.png) [@jon.giffard1](https://community.neo4j.com/u/jon.giffard1)\
**Post date:** [October 17, 2025, 8:32pm UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/2 "2025-10-17T20:32:29Z")

</div>

Hi

it looks like you need to set the uri to neo4j://localhost:7687

---

<div class="post-metadata">

**Author:** ![curtjef1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/curtjef1/32/36076_2.png) [@curtjef1](https://community.neo4j.com/u/curtjef1)\
**Post date:** [October 17, 2025, 9:10pm UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/3 "2025-10-17T21:10:16Z")

</div>

> [@jon.giffard1](#):
>
> it looks like you need to set the uri to neo4j://localhost:7687

Hi Jon,

I set uri to neo4j://localhost. Also, in the neo4j Desktop database, change the connection uri to same.

code:

…

uri = "neo4j://Localhost:7687"  
username = "neo4j"  
password = "…………."

```auto
try:
    greeter = SampleExample(uri, username, password)
    greeter.print_greeting("Welcome to neo4j")
    greeter.close()
except Exception as e:
    print(f"Error: {e}")
    print("Please ensure Neo4j is running and the connection details are correct")

```

error msg:

```auto
unable to retrieve routing information

```

```auto
Failed to connect to Neo4j: Unable to retrieve routing information
Error: Unable to retrieve routing information
Please ensure Neo4j is running and the connection details are correct

```

Note: As you can see, the last statement in error msg came from my try line.

---

<div class="post-metadata">

**Author:** ![jon.giffard1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jon.giffard1/32/34147_2.png) [@jon.giffard1](https://community.neo4j.com/u/jon.giffard1)\
**Post date:** [October 17, 2025, 9:31pm UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/4 "2025-10-17T21:31:45Z")

</div>

My apologies. I read your query too quickly and gave you incorrect information

If you have a single neo4j servers running, then the URI would be

bolt://localhost:7687

Can you try that and let me know?

Again, apologies for the bad steer.

Jonathan

---

<div class="post-metadata">

**Author:** ![curtjef1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/curtjef1/32/36076_2.png) [@curtjef1](https://community.neo4j.com/u/curtjef1)\
**Post date:** [October 17, 2025, 9:41pm UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/5 "2025-10-17T21:41:47Z")

</div>

Jonathan,

No apologies necessary. Just glad you’re helping.

Made recommended changes. BTW, Neo4j is running with instance in Running state. Still getting errors:

```auto
Failed to connect to Neo4j: Couldn't connect to Localhost:7687 (resolved to ('127.0.0.1:7687',)):
Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused)
Error: Couldn't connect to Localhost:7687 (resolved to ('127.0.0.1:7687',)):
Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused)

```

---

<div class="post-metadata">

**Author:** ![jon.giffard1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/jon.giffard1/32/34147_2.png) [@jon.giffard1](https://community.neo4j.com/u/jon.giffard1)\
**Post date:** [October 17, 2025, 10:11pm UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/6 "2025-10-17T22:11:36Z")

</div>

Lets try my go to for connecting to Neo4j using Python

```auto
# Use the Neo4j python driver
from neo4j import GraphDatabase

# The cypher statement
cypher_statement = 'MATCH (n) RETURN n LIMIT 1'

# Detail to connect to our Neo4j database
neo4_uri = 'bolt://localhost:7687'
neo4j_user = 'neo4j'
neo4j_password = 'password'

# Connect to Neo4j
neo4jDB_connection = GraphDatabase.driver(neo4_uri, keep_alive=True, auth=(neo4j_user, neo4j_password))

# Send the Cypher statement to Neo4j
neo4j_response = neo4jDB_connection.execute_query(cypher_statement)

# Print the response
print(neo4j_response.records)

```

Give that a try and see how you get on.

---

<div class="post-metadata">

**Author:** ![curtjef1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/curtjef1/32/36076_2.png) [@curtjef1](https://community.neo4j.com/u/curtjef1)\
**Post date:** [October 17, 2025, 10:25pm UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/7 "2025-10-17T22:25:33Z")

</div>

Still errors:

```auto
Transaction failed and will be retried in 0.9537840946055642s (Couldn't connect to localhost:7687 (resolved to ('127.0.0.1:7687',)):
Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused))
Transaction failed and will be retried in 1.9353899099803848s (Couldn't connect to localhost:7687 (resolved to ('127.0.0.1:7687',)):
Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused))
Transaction failed and will be retried in 3.89372432112062s (Couldn't connect to localhost:7687 (resolved to ('127.0.0.1:7687',)):
Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused))
Transaction failed and will be retried in 8.178613510251077s (Couldn't connect to localhost:7687 (resolved to ('127.0.0.1:7687',)):
Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused))
Transaction failed and will be retried in 18.406962404285593s (Couldn't connect to localhost:7687 (resolved to ('127.0.0.1:7687',)):
Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused))

```

Several lines following above error messages.

Here are half:

```auto
---------------------------------------------------------------------------
ConnectionRefusedError Traceback (most recent call last)
File ~/.local/lib/python3.11/site-packages/neo4j/_async_compat/network/_bolt_socket.py:498, in BoltSocketBase._connect_secure(cls, resolved_address, timeout, keep_alive, ssl_context)
    497 log.debug("[#0000] C: <OPEN> %s", resolved_address)
--> 498 s.connect(resolved_address)
    499 s.settimeout(t)

ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

ServiceUnavailable Traceback (most recent call last)
File ~/.local/lib/python3.11/site-packages/neo4j/_sync/io/_bolt_socket.py:329, in BoltSocket.connect(cls, address, tcp_timeout, deadline, custom_resolver, ssl_context, keep_alive)
    328 try:
--> 329 s = cls._connect_secure(
    330 resolved_address, tcp_timeout, keep_alive, ssl_context
    331 )
    332 agreed_version = s._handshake(resolved_address, deadline)

File ~/.local/lib/python3.11/site-packages/neo4j/_async_compat/network/_bolt_socket.py:521, in BoltSocketBase._connect_secure(cls, resolved_address, timeout, keep_alive, ssl_context)
    520 if isinstance(error, OSError):
--> 521 raise ServiceUnavailable(
    522 "Failed to establish connection to "
    523 f"{resolved_address!r} (reason {error})"
    524 ) from error
    525 raise

ServiceUnavailable: Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused)

The above exception was the direct cause of the following exception:

ServiceUnavailable Traceback (most recent call last)
Cell In[1], line 11
      9 neo4jDB_connection = GraphDatabase.driver(neo4_uri, keep_alive=True, auth=(neo4j_user, neo4j_password))
     10 # Send the Cypher statement to Neo4j
---> 11 neo4j_response = neo4jDB_connection.execute_query(cypher_statement)
     12 # Print the response
     13 print(neo4j_response.records)

File ~/.local/lib/python3.11/site-packages/neo4j/_sync/driver.py:946, in Driver.execute_query(self, query_, parameters_, routing_, database_, impersonated_user_, bookmark_manager_, auth_, result_transformer_, **kwargs)
    942 raise ValueError(
    943 f"Invalid routing control value: {routing_!r}"
    944 )
    945 with session._pipelined_begin:
--> 946 return session._run_transaction(
    947 access_mode,
    948 TelemetryAPI.DRIVER,
    949 work,
    950 (query_str, parameters, result_transformer_),
    951 {},
    952 )

File ~/.local/lib/python3.11/site-packages/neo4j/_sync/work/session.py:584, in Session._run_transaction(self, access_mode, api, transaction_function, args, kwargs)
    579 raise
    581 if errors:
    582 # TODO: 7.0 - when Python 3.11+ is the minimum,
    583 # use exception groups
--> 584 raise errors[-1]
    585 else:
    586 raise ServiceUnavailable("Transaction failed")

```

---

<div class="post-metadata">

**Author:** ![hakan.lofqvist1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/hakan.lofqvist1/32/10877_2.png) [@hakan.lofqvist1](https://community.neo4j.com/u/hakan.lofqvist1)\
**Post date:** [October 18, 2025, 8:12am UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/8 "2025-10-18T08:12:19Z")

</div>

Check that neo4j db is indeed running and that is listening to the port you expect. Test that it accepts connections on the port with netcat or other tool.

By the default, you should also have neo4j browser on [http://localhost:7474](http://localhost:7474) - try with that.

Then go to connecting with python. Check that you have the latest neo4j package for python.

By default the connection url for the driver should be neo4j://localhost:7687

---

<div class="post-metadata">

**Author:** ![curtjef1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/curtjef1/32/36076_2.png) [@curtjef1](https://community.neo4j.com/u/curtjef1)\
**Post date:** [October 19, 2025, 4:25am UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/9 "2025-10-19T04:25:51Z")

</div>

Jonathan/Hakan,

Turns out, the problem was that my version of python was running inside of Jupyter running in Anaconda. The host was not my machine, but something in a cloud environment.

I downloaded and install a local version of Jupyter/python and then the recommendations you presented worked!

Thanks for you help.

Curtis

---

<div class="post-metadata">

**Author:** ![hakan.lofqvist1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/hakan.lofqvist1/32/10877_2.png) [@hakan.lofqvist1](https://community.neo4j.com/u/hakan.lofqvist1)\
**Post date:** [October 20, 2025, 5:38am UTC](https://community.neo4j.com/t/cannot-connect-to-community-noe4j-2025-09-from-python-on-same-machine/75719/10 "2025-10-20T05:38:05Z")

</div>

These days, it is getting harder to keep track of what is running where 🙂 Glad to hear you were able to sort it out.
