Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SecurityError: Failed to establish secure connection to 'EOF occurred in violation of protocol (_ssl.c:841)'

I am attempting to connect to Neo4j but I keep getting this error. I tried

from neo4j.v1 import GraphDatabase
driver = GraphDatabase.driver(uri="bolt://localhost:7687", auth=("neo4j", "12345"))

but I get this error when I try to connect

SecurityError: Failed to establish secure connection to 'EOF occurred in violation of protocol (_ssl.c:841)'

I can connect to the browser when I type http://localhost:7474/browser/

Here is the full error log:

--------------------------------------------------------------------------- SSLEOFError Traceback (most recent call last) ~\AppData\Roaming\Python\Python36\site-packages\neobolt\direct.py in _secure(s, host, ssl_context, **config) 853 try: --> 854 s = ssl_context.wrap_socket(s, server_hostname=host if HAS_SNI and host else None) 855 except SSLError as cause:

c:\program files\python36\lib\ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session) 406 server_hostname=server_hostname, --> 407 _context=self, _session=session) 408

c:\program files\python36\lib\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) 813 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets") --> 814 self.do_handshake() 815

c:\program files\python36\lib\ssl.py in do_handshake(self, block)
1067 self.settimeout(None) -> 1068 self._sslobj.do_handshake() 1069 finally:

c:\program files\python36\lib\ssl.py in do_handshake(self) 688 """Start the SSL/TLS handshake.""" --> 689 self._sslobj.do_handshake() 690 if self.context.check_hostname:

SSLEOFError: EOF occurred in violation of protocol (_ssl.c:841)

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

SecurityError Traceback (most recent call last) in 1 ----> 2 driver = GraphDatabase.driver(uri="bolt://localhost:7687", auth=("neo4j", "12345"))

~\AppData\Roaming\Python\Python36\site-packages\neo4j__init__.py in driver(cls, uri, **config) 118 :class:.Driver subclass instance directly. 119 """ --> 120 return Driver(uri, **config) 121 122

~\AppData\Roaming\Python\Python36\site-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

~\AppData\Roaming\Python\Python36\site-packages\neo4j__init__.py in new(cls, uri, **config) 233 234 pool = ConnectionPool(connector, instance.address, **config) --> 235 pool.release(pool.acquire()) 236 instance._pool = pool 237 instance._max_retry_time = config.get("max_retry_time", default_config["max_retry_time"])

~\AppData\Roaming\Python\Python36\site-packages\neobolt\direct.py in acquire(self, access_mode) 713 714 def acquire(self, access_mode=None): --> 715 return self.acquire_direct(self.address) 716 717

~\AppData\Roaming\Python\Python36\site-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)

~\AppData\Roaming\Python\Python36\site-packages\neo4j__init__.py in connector(address, **kwargs) 230 231 def connector(address, **kwargs): --> 232 return connect(address, **dict(config, **kwargs)) 233 234 pool = ConnectionPool(connector, instance.address, **config)

~\AppData\Roaming\Python\Python36\site-packages\neobolt\direct.py in connect(address, **config) 970 raise ServiceUnavailable("Failed to resolve addresses for %s" % address) 971 else: --> 972 raise last_error

~\AppData\Roaming\Python\Python36\site-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:

~\AppData\Roaming\Python\Python36\site-packages\neobolt\direct.py in _secure(s, host, ssl_context, **config) 857 error = SecurityError("Failed to establish secure connection to {!r}".format(cause.args[1])) 858 error.cause = cause --> 859 raise error 860 else: 861 # Check that the server provides a certificate

SecurityError: Failed to establish secure connection to 'EOF occurred in violation of protocol (_ssl.c:841)'

like image 997
Sam Avatar asked Feb 02 '20 05:02

Sam


2 Answers

I had the same problem with the Object Graph Mapper Neomodel (connecting to neo4j v4). Adding the second line solved it:

config.DATABASE_URL = 'bolt://neo4j:password123@localhost:7687'
config.ENCRYPTED_CONNECTION = False
like image 178
El tornillo Avatar answered Sep 28 '22 08:09

El tornillo


I found the solution for people who might have the same issue. You need to add encrypted=False.

Instead of

from neo4j.v1 import GraphDatabase
driver = GraphDatabase.driver(uri="bolt://localhost:7687", auth=("neo4j", "12345"))

it should be:

driver = GraphDatabase.driver(uri="bolt://localhost:7687", auth=("neo4j", "12345"), encrypted=False)

Hope this will help someone

like image 26
Sam Avatar answered Sep 28 '22 08:09

Sam