2017-10-16 93 views
0

建立安全連接我試圖用neo4j-driver將Django連接到Neo4j,但出現安全錯誤。Python-Neo4j連接數據庫時出現安全錯誤無法與[[SSL:UNKNOWN_PROTCOL(_ssl.c:600)

錯誤是: - neo4j.exceptions.SecurityError: Failed to establish secure connection to '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:600)'

Python版本3.4.3 MACOSX

我的依賴

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") 

錯誤

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)' 

回答

1

感謝RISHABH用於寫入解決問題卸載Neo4j的驅動程序。

我後來認識到端口號7474用於http協議以供ssl使用。

我已經uri = "bolt://localhost:7474"改變URL形式uri = "bolt://localhost:7687"

工作就像魅力!

0

據報道,這在Github issue here。以下是否適合你?

  1. 使用pip uninstall neo4j-driver
  2. 執行命令echo "deb http://httpredir.debian.org/debian/ jessie-backports main" >> /etc/apt/sources.list && apt update && apt install -y -t jessie-backports openssl在終端
  3. 重新安裝的Neo4j驅動pip install neo4j-driver
+0

嗨@Rishabh Srivastava感謝您的答覆,但我使用的是一個macosx,所以這個回聲命令將無法正常工作,因爲它有更新和易於安裝 –

1

瀏覽器顯示端口9987,並且在使用此端口時出現異常。它工作時,我改變了蟒蛇端口7687

相關問題