cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to detour neo4j protocol or bolt protocol?

chun3842
Node

Hi, community!
I just installed and started Neo4j which looks very useful and gives fancy GUI.

But soon after, it turned out that Neo4j browser on port No. 7474 is working well though, the connection between my terminal and server is not made successfully.

I am guessing that the reason is security policy to block connections with any other protocols except HTTP(even https are not available now by the policy).
Neo4j browser with http://IPaddress:7474 works, however, when I tried to login into Neo4j browser(which force to use neo4j protocol with port No. 7687), it takes about 1~2min to complete the login. Also, for just one Cypher request on Neo4j browser, it takes a few minutes and finally gives error message.

// neo4j browser
ERROR: Session Expired

WebSocket connection failure. 
Due to security constraints in your web browser, 
the reason for the failure is not available to this Neo4j Driver. 
Please use your browsers development console to determine the root cause of the failure. 
Common reasons include the database being unavailable, using the wrong connection URL or temporary network problems. 
If you have enabled encryption, ensure your browser is configured to trust the certificate Neo4j is configured to use. 
WebSocket `readyState` is: 3

So, I tried python package, Neo4j and py2neo but also they give network error message mentioning hand shake.

// python, neo4j
...
driver = GraphDatabase.driver("neo4j://ip:7687", auth=("neo4j", "password"))
output>
OSError                                   Traceback (most recent call last)
<ipython-input-35-49ad3cab1b89> in <module>
      1 from neo4j import GraphDatabase
      2 
----> 3 driver = GraphDatabase.driver("neo4j://ip:7687", auth=("neo4j", "password"))
      4 
      5 def add_friend(tx, name, friend_name):

/usr/local/lib/python3.6/dist-packages/neo4j/__init__.py in driver(cls, uri, **config)
    118         :class:`.Driver` subclass instance directly.
    119         """
--> 120         return Driver(uri, **config)
    121 
    122 

/usr/local/lib/python3.6/dist-packages/neo4j/__init__.py in __new__(cls, uri, **config)
    159         for subclass in Driver.__subclasses__():
    160             if parsed_scheme in subclass.uri_schemes:
--> 161                 return subclass(uri, **config)
    162         raise ValueError("URI scheme %r not supported" % parsed.scheme)
    163 

/usr/local/lib/python3.6/dist-packages/neo4j/__init__.py in __new__(cls, uri, **config)
    276         pool = RoutingConnectionPool(connector, initial_address, routing_context, initial_address, **config)
    277         try:
--> 278             pool.update_routing_table()
    279         except:
    280             pool.close()

/usr/local/lib/python3.6/dist-packages/neobolt/routing.py in update_routing_table(self)
    371                 return
    372 
--> 373         if self.update_routing_table_from(*existing_routers):
    374             return
    375 

/usr/local/lib/python3.6/dist-packages/neobolt/routing.py in update_routing_table_from(self, *routers)
    350                   "{}".format(", ".join(map(repr, routers))))
    351         for router in routers:
--> 352             new_routing_table = self.fetch_routing_table(router)
    353             if new_routing_table is not None:
    354                 self.routing_table.update(new_routing_table)

/usr/local/lib/python3.6/dist-packages/neobolt/routing.py in fetch_routing_table(self, address)
    315         :raise ProtocolError: if the routing information received is unusable
    316         """
--> 317         new_routing_info = self.fetch_routing_info(address)
    318         if new_routing_info is None:
    319             return None

/usr/local/lib/python3.6/dist-packages/neobolt/routing.py in fetch_routing_info(self, address)
    289 
    290         try:
--> 291             with self.acquire_direct(address) as cx:
    292                 _, _, server_version = (cx.server.agent or "").partition("/")
    293                 if server_version and Version.parse(server_version) >= Version((3, 2)):

/usr/local/lib/python3.6/dist-packages/neobolt/direct.py in acquire_direct(self, address)
    606                 if can_create_new_connection:
    607                     try:
--> 608                         connection = self.connector(address, error_handler=self.connection_error_handler)
    609                     except ServiceUnavailable:
    610                         self.remove(address)

/usr/local/lib/python3.6/dist-packages/neo4j/__init__.py in connector(address, **kwargs)
    272 
    273         def connector(address, **kwargs):
--> 274             return connect(address, **dict(config, **kwargs))
    275 
    276         pool = RoutingConnectionPool(connector, initial_address, routing_context, initial_address, **config)

/usr/local/lib/python3.6/dist-packages/neobolt/direct.py in connect(address, **config)
    970         raise ServiceUnavailable("Failed to resolve addresses for %s" % address)
    971     else:
--> 972         raise last_error

/usr/local/lib/python3.6/dist-packages/neobolt/direct.py in connect(address, **config)
    961             host = address[0]
    962             s = _connect(resolved_address, **config)
--> 963             s, der_encoded_server_certificate = _secure(s, host, security_plan.ssl_context, **config)
    964             connection = _handshake(s, address, der_encoded_server_certificate, **config)
    965         except Exception as error:

/usr/local/lib/python3.6/dist-packages/neobolt/direct.py in _secure(s, host, ssl_context, **config)
    852         log_debug("[#%04X]  C: <SECURE> %s", local_port, host)
    853         try:
--> 854             s = ssl_context.wrap_socket(s, server_hostname=host if HAS_SNI and host else None)
    855         except SSLError as cause:
    856             s.close()

/usr/lib/python3.6/ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    405                          suppress_ragged_eofs=suppress_ragged_eofs,
    406                          server_hostname=server_hostname,
--> 407                          _context=self, _session=session)
    408 
    409     def wrap_bio(self, incoming, outgoing, server_side=False,

/usr/lib/python3.6/ssl.py in __init__(self, sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, family, type, proto, fileno, suppress_ragged_eofs, npn_protocols, ciphers, server_hostname, _context, _session)
    815                         # non-blocking
    816                         raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
--> 817                     self.do_handshake()
    818 
    819             except (OSError, ValueError):

/usr/lib/python3.6/ssl.py in do_handshake(self, block)
   1075             if timeout == 0.0 and block:
   1076                 self.settimeout(None)
-> 1077             self._sslobj.do_handshake()
   1078         finally:
   1079             self.settimeout(timeout)

/usr/lib/python3.6/ssl.py in do_handshake(self)
    687     def do_handshake(self):
    688         """Start the SSL/TLS handshake."""
--> 689         self._sslobj.do_handshake()
    690         if self.context.check_hostname:
    691             if not self.server_hostname:

OSError: [Errno 0] Error
// py2neo
...
graph = Graph('http://ip:7687/')
graph.delete_all()

output>
/usr/lib/python3.6/http/client.py in begin(self)
    305         # read until we get a non-100 response
    306         while True:
--> 307             version, status, reason = self._read_status()
    308             if status != CONTINUE:
    309                 break

/usr/lib/python3.6/http/client.py in _read_status(self)
    266 
    267     def _read_status(self):
--> 268         line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    269         if len(line) > _MAXLINE:
    270             raise LineTooLong("status line")

/usr/lib/python3.6/socket.py in readinto(self, b)
    584         while True:
    585             try:
--> 586                 return self._sock.recv_into(b)
    587             except timeout:
    588                 self._timeout_occurred = True

It would be greate there is a way to connect for Cypher on Neo4j browser via HTTP protocol or a way to convert the protocol at client-side.
Or is there a way to convert Cypher-shell query result table to diagrams?

Thank you in advance !

1 REPLY 1

Hi there,

Just to clarify, are you trying to connect to an Aura instance, or have you installed your own Neo4j server in a cloud provider? If so, which cloud provider are you using?

If you're using Aura then unfortunately HTTP isn't going to work. You'll need to connect using the neo4j protocol (or bolt+routing if using an older driver that's not yet compatible with neo4j scheme); you'll also need to make sure to explicitly set encryption to true. For instance:

driver = GraphDatabase.driver(GRAPH_URI,
                              auth= (GRAPH_USER,GRAPH_PASSWORD), 
                              encrypted=True)

HTTP connections to the database itself aren't exposed in Aura, though you can navigate to the browser interface using HTTPS.

If you're running your own server in a cloud provider then connecting will depend on how you have your security policies configured.

Cory

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.