cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to connect to Podman neo4J from Python

New to neo4j. Trying to set up an environment to prototype an idea, and I am being very unlucky using Python to connect to a neo4j running in Podman, no K8s, no fanciness, just a straight-up container. 

1) Setup:
Running macOS M1, Monterey 12.5

2) neo4j running in podman:
podman run --add-host=neo4j:127.0.0.1 -p7474:7474 -p7687:7687 -d --env NEO4J_AUTH=neo4j/test neo4j:latest

(I am able to connect to the instance via web browser and do queries etc at http://localhost:7474)

3) From macOS in the host OS, I am running a virtual environment with Python 3.9.1. My script:

``'''

from neo4j import GraphDatabase

driver = GraphDatabase.driver("neo4j://127.0.0.1:7474",auth=("neo4j", "test"))

driver.verify_connectivity()

'''
(also tried with localhost instead of the IP address)

4) Results I am getting (from Python shell):

<stdin>:1: ExperimentalWarning: The configuration may change in the future.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/barnysanchez/.pyenv/versions/class/lib/python3.9/site-packages/neo4j/meta.py", line 85, in f_
return f(*args, **kwargs)
File "/Users/barnysanchez/.pyenv/versions/class/lib/python3.9/site-packages/neo4j/__init__.py", line 435, in verify_connectivity
return self._verify_routing_connectivity()
File "/Users/barnysanchez/.pyenv/versions/class/lib/python3.9/site-packages/neo4j/__init__.py", line 461, in _verify_routing_connectivity
raise ServiceUnavailable("Could not connect to any routing servers.")
neo4j.exceptions.ServiceUnavailable: Could not connect to any routing servers.

Please any clues or pushes in the right direction will be greatly appreciated.

 

1 ACCEPTED SOLUTION

Hi Community:  I am responding to my own question hoping that it can help at least 1 person and spare you a good amount of time testing to get it right.

1) What was my intention/purpose?

Setup a Podman container running neo4j and then from a virtual environment in my macOS, running Python 3.9.1, connect to my neo4J and go at it.

2) What problem did I face?

You can see those details up in this thread, that's when I wrote to the community for assistance.

3) What did I do?
I read/analyze the information in the following links...
https://community.neo4j.com/t5/drivers-stacks/could-not-open-a-new-neo4j-session-unable-to-connect-t...
https://neo4j.com/docs/operations-manual/current/reference/configuration-settings/

I then spent a little time with my podman config based on that. Please refer to the picture attached but this is how I started my container:

podman run \
--publish=7474:7474 --publish=7687:7687 \
--env NEO4J_dbms_connector_http_advertised__address=0.0.0.0 \
--env NEO4J_dbms_connector_bolt_advertised__address=0.0.0.0 \
--env NEO4J_dbms_connector_https_advertised__address=0.0.0.0 \
--env NEO4J_AUTH=neo4j/test \
--name neo4j \
--env NEO4J_dbms_default__listen__address=0.0.0.0 \
neo4j:latest

I purposefully started the container in attached mode so I could scan for errors or others.

One thing caught my attention (yellow circle in the picture) is that while the remote interface was available via the port 7474, the bolt was enabled on 7687.

Armed with this I modified my driver configuration to look like this:

from neo4j import GraphDatabase
driver = GraphDatabase.driver("neo4j://localhost:7687",auth=("neo4j", "test"))

And voilá!  now the connectivity was confirmed:

driver.verify_connectivity()

{IPv4Address(('localhost', 7687)): [{'servers': [{'addresses': ['localhost:7687'],
     'role': 'WRITE'},
    {'addresses': ['localhost:7687'], 'role': 'READ'},
    {'addresses': ['localhost:7687'], 'role': 'ROUTE'}],
   'ttl': 300,
   'db': 'neo4j'}]}

 podman.pngpodman2.png

View solution in original post

1 REPLY 1

Hi Community:  I am responding to my own question hoping that it can help at least 1 person and spare you a good amount of time testing to get it right.

1) What was my intention/purpose?

Setup a Podman container running neo4j and then from a virtual environment in my macOS, running Python 3.9.1, connect to my neo4J and go at it.

2) What problem did I face?

You can see those details up in this thread, that's when I wrote to the community for assistance.

3) What did I do?
I read/analyze the information in the following links...
https://community.neo4j.com/t5/drivers-stacks/could-not-open-a-new-neo4j-session-unable-to-connect-t...
https://neo4j.com/docs/operations-manual/current/reference/configuration-settings/

I then spent a little time with my podman config based on that. Please refer to the picture attached but this is how I started my container:

podman run \
--publish=7474:7474 --publish=7687:7687 \
--env NEO4J_dbms_connector_http_advertised__address=0.0.0.0 \
--env NEO4J_dbms_connector_bolt_advertised__address=0.0.0.0 \
--env NEO4J_dbms_connector_https_advertised__address=0.0.0.0 \
--env NEO4J_AUTH=neo4j/test \
--name neo4j \
--env NEO4J_dbms_default__listen__address=0.0.0.0 \
neo4j:latest

I purposefully started the container in attached mode so I could scan for errors or others.

One thing caught my attention (yellow circle in the picture) is that while the remote interface was available via the port 7474, the bolt was enabled on 7687.

Armed with this I modified my driver configuration to look like this:

from neo4j import GraphDatabase
driver = GraphDatabase.driver("neo4j://localhost:7687",auth=("neo4j", "test"))

And voilá!  now the connectivity was confirmed:

driver.verify_connectivity()

{IPv4Address(('localhost', 7687)): [{'servers': [{'addresses': ['localhost:7687'],
     'role': 'WRITE'},
    {'addresses': ['localhost:7687'], 'role': 'READ'},
    {'addresses': ['localhost:7687'], 'role': 'ROUTE'}],
   'ttl': 300,
   'db': 'neo4j'}]}

 podman.pngpodman2.png