Skip to content

Commit cd78511

Browse files
committed
Merge pull request #66 from pontusmelke/1.0-error-msg-http
Better error message when connecting to http port
2 parents 88c4c78 + 4ac8440 commit cd78511

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

neo4j/v1/connection.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,5 +442,12 @@ def connect(host, port=None, ssl_context=None, **config):
442442
if __debug__: log_info("~~ [CLOSE]")
443443
s.shutdown(SHUT_RDWR)
444444
s.close()
445-
else:
445+
elif agreed_version == 1:
446446
return Connection(s, der_encoded_server_certificate=der_encoded_server_certificate, **config)
447+
elif agreed_version == 1213486160:
448+
log_error("S: [CLOSE]")
449+
raise ProtocolError("Server responded HTTP. Make sure you are not trying to connect to the http endpoint " +
450+
"(HTTP defaults to port 7474 whereas BOLT defaults to port 7687)")
451+
else:
452+
log_error("S: [CLOSE]")
453+
raise ProtocolError("Unknown Bolt protocol version: %d", agreed_version)

test/test_session.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ def test_sessions_are_not_reused_if_still_in_use(self):
9090
session_1.close()
9191
assert session_1 is not session_2
9292

93+
def test_fail_nicely_when_connecting_to_http_port(self):
94+
driver = GraphDatabase.driver("bolt://localhost:7474", auth=auth_token, encrypted=False)
95+
with self.assertRaises(ProtocolError) as context:
96+
driver.session()
97+
98+
assert str(context.exception) == "Server responded HTTP. Make sure you are not trying to connect to the http " \
99+
"endpoint (HTTP defaults to port 7474 whereas BOLT defaults to port 7687)"
100+
101+
93102

94103
class SecurityTestCase(ServerTestCase):
95104

0 commit comments

Comments
 (0)