cancel
Showing results for 
Search instead for 
Did you mean: 

(Unable to retrieve routing information

okamoun
Node Link

HI , I am new to Neo4j I tried initially to access it via python on google colab and it worked well, when I tryied from puython runing on mt machine I get (Unable to retrieve routing information), my connection string is uri = "neo4j+s://b680a66a.databases.neo4j.io" and it is running for Mac ( tried intel and M1 )

12 REPLIES 12

andreperez
Graph Buddy

Could you share some code?

from neo4j import GraphDatabase
import logging
from neo4j.exceptions import ServiceUnavailable

class App:

def __init__(self, uri, user, password):
    self.driver = GraphDatabase.driver(uri, auth=(user, password))

def close(self):
    # Don't forget to close the driver connection when you are finished with it
    self.driver.close()

def create_friendship(self, person1_name, person2_name):
    with self.driver.session() as session:
        # Write transactions allow the driver to handle retries and transient errors
        result = session.write_transaction(
            self._create_and_return_friendship, person1_name, person2_name)
        for row in result:
            print("Created friendship between: {p1}, {p2}".format(p1=row['p1'], p2=row['p2']))

@staticmethod
def _create_and_return_friendship(tx, person1_name, person2_name):
    # To learn more about the Cypher syntax, see https://neo4j.com/docs/cypher-manual/current/
    # The Reference Card is also a good resource for keywords https://neo4j.com/docs/cypher-refcard/current/
    query = (
        "CREATE (p1:Person { name: $person1_name }) "
        "CREATE (p2:Person { name: $person2_name }) "
        "CREATE (p1)-[:KNOWS]->(p2) "
        "RETURN p1, p2"
    )
    result = tx.run(query, person1_name=person1_name, person2_name=person2_name)
    try:
        return [{"p1": row["p1"]["name"], "p2": row["p2"]["name"]}
                for row in result]
    # Capture any errors along with the query and data for traceability
    except ServiceUnavailable as exception:
        logging.error("{query} raised an error: \n {exception}".format(
            query=query, exception=exception))
        raise

def find_person(self, person_name):
    with self.driver.session() as session:
        result = session.read_transaction(self._find_and_return_person, person_name)
        for row in result:
            print("Found person: {row}".format(row=row))

@staticmethod
def _find_and_return_person(tx, person_name):
    query = (
        "MATCH (p:Person) "
        "WHERE p.name = $person_name "
        "RETURN p.name AS name"
    )
    result = tx.run(query, person_name=person_name)
    return [row["name"] for row in result]

if name == "main":
# Aura queries use an encrypted connection using the "neo4j+s" URI scheme
uri = "neo4j://b680a66a.databases.neo4j.io"
user = "neo4j"
password = "XXXX"
app = App(uri, user, password)
app.create_friendship("Alice", "David")
app.find_person("Alice")
app.close()

Shouldn't this be neo4j+s:// to match the protocol?

thanks with 3.9 and the fix on the uri it is working

andreperez
Graph Buddy

In this topic there was a problem with the python version that was being used. Could you try to verify this?

Thanks fo the suggestion I was using 3.8 I tried with 3.9 but it gave same error . On colab it works fine with 3.7 , locally I tried 3.8, 3.7 and 3.9 and they gave the same error. Wonder if it is link to OS X or with my network

casselldev
Node

Hello, I am currently dealing with this exact same problem, however changing the python version did not work for me.

I am attempting to connect to aura using the latest driver version, using the same 'connect' example code. I have tried various combinations of python/driver versions (3.8-3.9, 4.1-4.4 respectively), and always get 'Unable to retrieve routing information'.
Upon further digging, looks like I'm getting a BoltSecurityError: [SSLCertVerificationError]:

"Connection Failed. Please ensure that your database is listening on the correct host and port and that you have enabled encryption if required. Note that the default encryption setting has changed in Neo4j 4.0. See the docs for more information. Failed to establish encrypted connection. (code 1: Operation not permitted)"

Interestingly, the javascript version of this code works without any issues whatsoever with my aura db. Any help in tracking down this python issue would be incredibly appreciated.

Interestingly, trying this on Google Colab with the exact same python versions worked. Seems like this issue may be limited to python locally running on my machine (Mac OS 10.15). Any ideas?

casselldev
Node

For anyone that comes across this issue later on, I finally resolved this. Under the hood this was an SSL error.

Make sure you have a root certificate installed. In my case, I installed my python version using the Mac package installer from python.org - that automatically downloads a 'Install Certificates' script. Run that and you'll be good to go.

anystack100
Node Link

Just chiming in with another solution that helped me get around the "Unable to retrieve routing information" error when I moved from a local to an Aura connection.

I am able to use Python 3.8.1. I found that I needed to update my version of the neo4j module from 4.2.1 to 4.4.1.

I also found that at some stage during troubleshooting I had dropped "+s" from the "neo4j+s://" bit of the URI. Re-adding "+s" ultimately got me past the error.

Also really valuable for debugging is this snippet rouven.bauer posted:

from neo4j import GraphDatabase
from neo4j.debug import watch

uri = "..."
driver = GraphDatabase.driver(uri, auth=("neo4j", "password123"))

def workload(tx):
    return tx.run("RETURN 1 as n").data()

with watch("neo4j"):  # enable logging
    with driver.session() as session:
        session.write_transaction(workload)

driver.close()

That showed me the underlying "Connection to :7687 closed without handshake response" error, once I updated the neo4j module.

Some useful docs:

I am unable to connect to the Aura database from Cloud Run on GCP. It gives the same error: neo4j.exceptions.ServiceUnavailable: Unable to retrieve routing information. I am using the following to connect to the database: driver = GraphDatabase.driver(GRAPH_URL, auth=(GRAPH_USER,GRAPH_PASS)), where GRAPH_URL=neo4j+s://<id>.databases.neo4j.io (also included the port 7687. I am able to log in on the Neo4j Browser app and can confirm the queries work from there, as well as locally from my virtual environment and docker container all running Python 3.9 (GCP Cloud Run also runs off of docker containers).

I've already tried:

  1. Versions

      Neo4j versions:
     * Neo4j 4.4
     * Neo4j 4.3
     * Neo4j 3.5
     
     Python versions:
     
     * Python 3.9
     * Python 3.8
     * Python 3.7
     * Python 3.6
    
  2. Certificates:

CERT_PATH=$(python -m certifi)
export SSL_CERT_FILE=${CERT_PATH}
export REQUESTS_CA_BUNDLE=${CERT_PATH}
  1. Encryption:
    Use neo4j+s and neo4j+ssc

  2. Auth
    Using basic_auth for the auth=basic_auth(GRAPH_USER,GRAPH_PASS) parameter.

  3. Firewall
    It could be a firewall issue. I added a firewall rule to allow all EGRESS traffic to all ports to the IP address 104.197.20.211. Our instance is in Iowa, US. (https://aura.support.neo4j.com/hc/en-us/articles/360050504254-What-are-the-public-IP-addresses-to-pr...).

In the error logs, you'll notice that the error happens not on instantiating the driver instance, but by doing a driver.session().read_transaction(fn).

Code Below:

from neo4j import GraphDatabase
import os

def get_db():
    GRAPH_URL = os.environ.get("GRAPH_URL")
    GRAPH_USER = os.environ.get("GRAPH_USER")
    GRAPH_PASS = os.environ.get("GRAPH_PASS")
    driver = GraphDatabase.driver(GRAPH_URL, auth=(GRAPH_USER,GRAPH_PASS))
    return driver.session()

def get_catalog_from_graph(tx):
    catalog = []

    result = tx.run(
        """
        MATCH (a:AssetNorth)
        RETURN a
        """,
    )

    for record in result.data():
        catalog.append(record["a"])

    return catalog

def get_catalog():
    neo_db = get_db()
    results = neo_db.read_transaction(get_catalog_from_graph)
    return results

get_catalog()

Docker Image: python:3.9-slim-bullseye

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2095, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2080, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.9/site-packages/flask/views.py", line 84, in view
    return current_app.ensure_sync(self.dispatch_request)(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/flask/views.py", line 158, in dispatch_request
    return current_app.ensure_sync(meth)(*args, **kwargs)
  File "/tardis/app/catalog/list.py", line 39, in get
    catalog = getattr(eval(user_db), "get_catalog")()
  File "/tardis/app/lineage/helpers/northwind.py", line 225, in get_catalog
    results = neo_db.read_transaction(get_catalog_from_graph)
  File "/usr/local/lib/python3.9/site-packages/neo4j/work/simple.py", line 396, in read_transaction
    return self._run_transaction(READ_ACCESS, transaction_function, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/neo4j/work/simple.py", line 352, in _run_transaction
    raise errors[-1]
  File "/usr/local/lib/python3.9/site-packages/neo4j/work/simple.py", line 322, in _run_transaction
    self._open_transaction(access_mode=access_mode, metadata=metadata, timeout=timeout)
  File "/usr/local/lib/python3.9/site-packages/neo4j/work/simple.py", line 255, in _open_transaction
    self._connect(access_mode=access_mode)
  File "/usr/local/lib/python3.9/site-packages/neo4j/work/simple.py", line 108, in _connect
    super()._connect(access_mode)
  File "/usr/local/lib/python3.9/site-packages/neo4j/work/__init__.py", line 73, in _connect
    self._pool.update_routing_table(
  File "/usr/local/lib/python3.9/site-packages/neo4j/io/__init__.py", line 1103, in update_routing_table
    raise ServiceUnavailable("Unable to retrieve routing information")
neo4j.exceptions.ServiceUnavailable: Unable to retrieve routing information

Another thing is that Neo4j offers a GCP integration. Is that neccessary to connect to the Aura database (https://aura.support.neo4j.com/hc/en-us/articles/360044842293-Getting-Started-with-Neo4j-Aura-for-GC...)?

Thanks!

I figured it out. I had a VPC Access Connector that was all traffic for Cloud Run was passing through. Even when it was turn on an Egress Firewall rule that applied to the VPC Connector (using tags), it still didn't work. I had to reconfigure the the VPC Connector options to be "Route only requests to private IPs through the VPC connector".

Something I haven't tried is to setup a static IP address for the VPC Connector (Dirección IP saliente estática  |  Documentación de Cloud Run  |  Google Cloud). This could work