cancel
Showing results for 
Search instead for 
Did you mean: 

Neo4j <> Cartography ConnectionRefusedError

steves
Node Clone

I am getting the following error when running docker compose but when I go to `bolt://localhost:7687` I do get the graph and all the labels and nodes.
Dockerfile and Docker compose are attached.

ERROR:neo4j:Unable to retrieve routing information
cartography-cartography-1 | Traceback (most recent call last):
cartography-cartography-1 | File "/usr/local/bin/cartography", line 33, in <module>
cartography-cartography-1 | sys.exit(load_entry_point('cartography', 'console_scripts', 'cartography')())
cartography-cartography-1 | File "/var/cartography/cartography/cli.py", line 553, in main
cartography-cartography-1 | sys.exit(CLI(default_sync, prog='cartography').main(argv))
cartography-cartography-1 | File "/var/cartography/cartography/cli.py", line 533, in main
cartography-cartography-1 | return cartography.sync.run_with_config(self.sync, config)
cartography-cartography-1 | File "/var/cartography/cartography/sync.py", line 163, in run_with_config
cartography-cartography-1 | return sync.run(neo4j_driver, config)
cartography-cartography-1 | File "/var/cartography/cartography/sync.py", line 81, in run
cartography-cartography-1 | with neo4j_driver.session() as neo4j_session:
cartography-cartography-1 | File "/var/cartography/cartography/experimental_neo4j_4x_support.py", line 167, in wrapper
cartography-cartography-1 | patch_session_obj(neo4j_session)
cartography-cartography-1 | File "/var/cartography/cartography/experimental_neo4j_4x_support.py", line 155, in patch_session_obj
cartography-cartography-1 | detect_neo4j_version(neo4j_session)
cartography-cartography-1 | File "/var/cartography/cartography/experimental_neo4j_4x_support.py", line 143, in detect_neo4j_version
cartography-cartography-1 | result = neo4j_session.run(
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/work/simple.py", line 204, in run
cartography-cartography-1 | self._connect(self._config.default_access_mode)
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/work/simple.py", line 108, in _connect
cartography-cartography-1 | super()._connect(access_mode)
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/work/__init__.py", line 75, in _connect
cartography-cartography-1 | self._pool.update_routing_table(
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/__init__.py", line 1213, in update_routing_table
cartography-cartography-1 | raise ServiceUnavailable("Unable to retrieve routing information")
cartography-cartography-1 | neo4j.exceptions.ServiceUnavailable: Unable to retrieve routing information
cartography-cartography-1 | INFO:cartography.sync:Starting sync with update tag '1661424422'
cartography-cartography-1 | Traceback (most recent call last):
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/_socket.py", line 147, in _connect
cartography-cartography-1 | s.connect(resolved_address)
cartography-cartography-1 | ConnectionRefusedError: [Errno 111] Connection refused
cartography-cartography-1 |
cartography-cartography-1 | During handling of the above exception, another exception occurred:
cartography-cartography-1 |
cartography-cartography-1 | Traceback (most recent call last):
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/_socket.py", line 284, in connect
cartography-cartography-1 | s = BoltSocket._connect(resolved_address, timeout, keep_alive)
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/_socket.py", line 164, in _connect
cartography-cartography-1 | raise ServiceUnavailable(
cartography-cartography-1 | neo4j.exceptions.ServiceUnavailable: Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused)
cartography-cartography-1 |
cartography-cartography-1 | The above exception was the direct cause of the following exception:
cartography-cartography-1 |
cartography-cartography-1 | Traceback (most recent call last):
cartography-cartography-1 | File "/usr/local/bin/cartography", line 33, in <module>
cartography-cartography-1 | sys.exit(load_entry_point('cartography', 'console_scripts', 'cartography')())
cartography-cartography-1 | File "/var/cartography/cartography/cli.py", line 553, in main
cartography-cartography-1 | sys.exit(CLI(default_sync, prog='cartography').main(argv))
cartography-cartography-1 | File "/var/cartography/cartography/cli.py", line 533, in main
cartography-cartography-1 | return cartography.sync.run_with_config(self.sync, config)
cartography-cartography-1 | File "/var/cartography/cartography/sync.py", line 163, in run_with_config
cartography-cartography-1 | return sync.run(neo4j_driver, config)
cartography-cartography-1 | File "/var/cartography/cartography/sync.py", line 81, in run
cartography-cartography-1 | with neo4j_driver.session() as neo4j_session:
cartography-cartography-1 | File "/var/cartography/cartography/experimental_neo4j_4x_support.py", line 167, in wrapper
cartography-cartography-1 | patch_session_obj(neo4j_session)
cartography-cartography-1 | File "/var/cartography/cartography/experimental_neo4j_4x_support.py", line 155, in patch_session_obj
cartography-cartography-1 | detect_neo4j_version(neo4j_session)
cartography-cartography-1 | File "/var/cartography/cartography/experimental_neo4j_4x_support.py", line 143, in detect_neo4j_version
cartography-cartography-1 | result = neo4j_session.run(
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/work/simple.py", line 204, in run
cartography-cartography-1 | self._connect(self._config.default_access_mode)
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/work/simple.py", line 108, in _connect
cartography-cartography-1 | super()._connect(access_mode)
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/work/__init__.py", line 82, in _connect
cartography-cartography-1 | self._connection = self._pool.acquire(
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/__init__.py", line 926, in acquire
cartography-cartography-1 | return self._acquire(self.address, deadline)
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/__init__.py", line 801, in _acquire
cartography-cartography-1 | return connection_creator()
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/__init__.py", line 729, in connection_creator
cartography-cartography-1 | connection = self.opener(
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/__init__.py", line 907, in opener
cartography-cartography-1 | return Bolt.open(
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/__init__.py", line 327, in open
cartography-cartography-1 | s, pool_config.protocol_version, handshake, data = BoltSocket.connect(
cartography-cartography-1 | File "/usr/local/lib/python3.9/site-packages/neo4j/io/_socket.py", line 311, in connect
cartography-cartography-1 | raise ServiceUnavailable(
cartography-cartography-1 | neo4j.exceptions.ServiceUnavailable: Couldn't connect to localhost:7687 (resolved to ('127.0.0.1:7687', '[::1]:7687')):
cartography-cartography-1 | Failed to establish connection to ResolvedIPv4Address(('127.0.0.1', 7687)) (reason [Errno 111] Connection refused)
cartography-cartography-1 | Failed to establish connection to ResolvedIPv6Address(('::1', 7687, 0, 0)) (reason [Errno 99] Cannot assign requested address)
cartography-cartography-1 exited with code 1


Docker compose:

version: "3.7"
services:
neo4j:
image: neo4j:4.4.5-community
restart: unless-stopped
ports:
- "7474:7474"
- "7687:7687"
volumes:
- ./.compose/neo4j/conf:/conf
- ./.compose/neo4j/data:/data
- ./.compose/neo4j/import:/import
- ./.compose/neo4j/logs:/logs
- ./.compose/neo4j/plugins:/plugins
environment:
# Raise memory limits:
- dbms.memory.pagecache.size=1G
- dbms.memory.heap.initial_size=1G
- dbms.memory.heap.max_size=1G
# Auth:
- NEO4J_AUTH=none
# Add APOC and GDS:
- apoc.export.file.enabled=true
- apoc.import.file.enabled=true
- apoc.import.file.use_neo4j_config=true
- NEO4JLABS_PLUGINS=["apoc", "graph-data-science"]
- dbms.security.procedures.allowlist=gds.*, apoc.*
- dbms.security.procedures.unrestricted=gds.*, apoc.*
# Networking:
- dbms.default_listen_address=0.0.0.0
- dbms.connector.bolt.listen_address=:7687

healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:7474"]
interval: 10s
timeout: 10s
retries: 10
cartography:
build:
context: .
dockerfile: dist.Dockerfile
init: true
restart: on-failure
depends_on:
- neo4j
environment:
- EXPERIMENTAL_NEO4J_4X_SUPPORT=True
volumes:
- /Users/stevesolun/.aws:/root/.aws/

Dockerfile:

FROM python:3.9-slim

# the UID and GID to run cartography as
# (https://github.com/hexops/dockerfile#do-not-use-a-uid-below-10000).
ARG uid=0 #10001
ARG gid=0 #10001

COPY . /var/cartography
WORKDIR /var/cartography

RUN apt-get update --fix-missing
RUN apt --allow-unauthenticated update -y
RUN apt-get install vim telnet curl gcc -y

RUN pip install -U -e .

USER ${uid}:${gid}


# verify that the binary at least runs
RUN cartography -h

ENTRYPOINT ["cartography"]

CMD ["-v", "--neo4j-uri=bolt://localhost:7687", "--aws-sync-all-profiles"]

1 REPLY 1

giuseppe_villan
Graph Fellow

@steves 

I don't know what the `/var/cartography` things are, but I think your problem is that you are trying to connect to another container using `localhost`. In general, you should connect using `localhost` outside the container.

I think that to solve this,
you need to add in the`docker-compose.yml` ' file the block ```

```    networks:

      - apoc_workshop

```

for eachservice,
at the end of the file ``

networks:

  apoc_workshop:

    driver: bridge`

 


and should change `--neo4j-uri=bolt://localhost:7687` to` --neo4j-uri=bolt://neo4j:7687`, basically you have to connect using the hostname of the other container, in your case `neo4j`.

See here for other details: https://linuxhint.com/docker_compose_bridge_networking/

 

If the problem persists, can you provide the complete example, including the ``var/cartography` files?

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.