Im trying to connect the Django to Neo4j using neo4j-driver but I'm getting Security error.
Error is :- neo4j.exceptions.SecurityError: Failed to establish secure connection to '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:600)'
Python Version 3.4.3 IN MACOSX
My Dependencies
django1.9
neo4j-driver==1.4.0
CODE Views.py
from django.shortcuts import render
# Create your views here.
from neo4j.v1 import GraphDatabase,basic_auth
from django.conf import settings
from django.db import IntegrityError
from django.views.decorators.cache import cache_page
from django.http import HttpResponse
from django.contrib import messages
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse,Http404
from django.http import StreamingHttpResponse
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django import template
uri = "bolt://localhost:7474"
driver = GraphDatabase.driver(uri, auth=("neo4j", "password"))
def friends(request):
name = "Cameron Crowe"
with driver.session() as session:
with session.begin_transaction() as tx:
for record in tx.run("MATCH (a:Person)-[:PRODUCED]->(f) "
"WHERE a.name = {name} "
"RETURN f.title", name=name):
print(record["f.title"])
return render(request, "friends.html")
Error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/core/checks/urls.py", line 10, in check_url_config
return check_resolver(resolver)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/core/checks/urls.py", line 19, in check_resolver
for pattern in resolver.url_patterns:
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/Users/sskadit/Desktop/graphdb/src/neo4/neo4/urls.py", line 19, in <module>
from graphdb.views import friends
File "/Users/sskadit/Desktop/graphdb/src/neo4/graphdb/views.py", line 20, in <module>
driver = GraphDatabase.driver("bolt://127.0.0.1:7474", auth= basic_auth("neo4j", "aditya369")).session()
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/neo4j/v1/api.py", line 124, in driver
return driver_class(uri, **config)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/neo4j/v1/direct.py", line 65, in __init__
pool.release(pool.acquire())
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/neo4j/v1/direct.py", line 39, in acquire
connection = self.acquire_direct(address) # should always be a resolved address
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/neo4j/bolt/connection.py", line 398, in acquire_direct
connection = self.connector(address)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/neo4j/v1/direct.py", line 64, in <lambda>
pool = DirectConnectionPool(lambda a: connect(a, security_plan.ssl_context, **config), self.address)
File "/Users/sskadit/Desktop/graphdb/src/lib/python3.4/site-packages/neo4j/bolt/connection.py", line 501, in connect
raise error
neo4j.exceptions.SecurityError: Failed to establish secure connection to '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:600)'
Thanks Rishabh for writing a solution to the question.
I later realized that port number 7474 is used for http protocol for ssl use.
I have changed the URL form uri = "bolt://localhost:7474"
to uri = "bolt://localhost:7687"
Worked like charm !!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With