将py2neo v4连接到我的neo4j服务器的问题

时间:2019-01-25 12:01:43

标签: neo4j py2neo keyerror

我想将我的neo4j的项目服务器连接到jupyter中的py2neo 我实际上有2个问题: 下面是我的neo4j浏览器的图片,该浏览器与bolt //:localhost:11004连接,用户名: neo4j ,密码:密码 但是我无法通过Jupyter Notebook上的py2neo连接到此服务器。 python中的代码如下: graphdb = Graph("bolt://localhost:11004", secure=True, auth=('neo4j', 'password')) 我收到以下错误:

KeyError                                  Traceback (most recent call last)
~/conda3/lib/python3.6/site-packages/py2neo/database.py in __new__(cls, uri, **settings)
     87         try:
---> 88             inst = cls._instances[key]
     89         except KeyError:

KeyError: '0611fb007d1a660e26e66e58777225de'

During handling of the above exception, another exception occurred:

ServiceUnavailable                        Traceback (most recent call last)
<ipython-input-41-2d6567e9c5ba> in <module>()
      3 # default uri for local Neo4j instance
      4 dict_params=dict(secure=True)
----> 5 graphdb = Graph(**dict_params)

~/conda3/lib/python3.6/site-packages/py2neo/database.py in __new__(cls, uri, **settings)
    303     def __new__(cls, uri=None, **settings):
    304         name = settings.pop("name", "data")
--> 305         database = Database(uri, **settings)
    306         if name in database:
    307             inst = database[name]

~/conda3/lib/python3.6/site-packages/py2neo/database.py in __new__(cls, uri, **settings)
     95                                   auth=connection_data["auth"],
     96                                   encrypted=connection_data["secure"],
---> 97                                   user_agent=connection_data["user_agent"])
     98             inst._graphs = {}
     99             cls._instances[key] = inst

~/conda3/lib/python3.6/site-packages/neo4j/v1/api.py in __new__(cls, uri, **config)
    131         for subclass in Driver.__subclasses__():
    132             if parsed.scheme == subclass.uri_scheme:
--> 133                 return subclass(uri, **config)
    134         raise ValueError("URI scheme %r not supported" % parsed.scheme)
    135 

~/conda3/lib/python3.6/site-packages/neo4j/v1/direct.py in __new__(cls, uri, **config)
     71 
     72         pool = DirectConnectionPool(connector, instance.address, **config)
---> 73         pool.release(pool.acquire())
     74         instance._pool = pool
     75         instance._max_retry_time = config.get("max_retry_time", default_config["max_retry_time"])

~/conda3/lib/python3.6/site-packages/neo4j/v1/direct.py in acquire(self, access_mode)
     42 
     43     def acquire(self, access_mode=None):
---> 44         return self.acquire_direct(self.address)
     45 
     46 

~/conda3/lib/python3.6/site-packages/neo4j/bolt/connection.py in acquire_direct(self, address)
    448                 if can_create_new_connection:
    449                     try:
--> 450                         connection = self.connector(address, self.connection_error_handler)
    451                     except ServiceUnavailable:
    452                         self.remove(address)

~/conda3/lib/python3.6/site-packages/neo4j/v1/direct.py in connector(address, error_handler)
     68 
     69         def connector(address, error_handler):
---> 70             return connect(address, security_plan.ssl_context, error_handler, **config)
     71 
     72         pool = DirectConnectionPool(connector, instance.address, **config)

~/conda3/lib/python3.6/site-packages/neo4j/bolt/connection.py in connect(address, ssl_context, error_handler, **config)
    702         raise ServiceUnavailable("Failed to resolve addresses for %s" % address)
    703     else:
--> 704         raise last_error

~/conda3/lib/python3.6/site-packages/neo4j/bolt/connection.py in connect(address, ssl_context, error_handler, **config)
    692         log_debug("~~ [RESOLVED] %s -> %s", address, resolved_address)
    693         try:
--> 694             s = _connect(resolved_address, **config)
    695             s, der_encoded_server_certificate = _secure(s, address[0], ssl_context, **config)
    696             connection = _handshake(s, resolved_address, der_encoded_server_certificate, error_handler, **config)

~/conda3/lib/python3.6/site-packages/neo4j/bolt/connection.py in _connect(resolved_address, **config)
    582         _force_close(s)
    583         if error.errno in (61, 99, 111, 10061):
--> 584             raise ServiceUnavailable("Failed to establish connection to {!r} (reason {})".format(resolved_address, error.errno))
    585         else:
    586             raise

ServiceUnavailable: Failed to establish connection to ('127.0.0.1', 7687) (reason 111)

我想知道的是  1)在py2neo v4中如何精确地建立neo4j和py2neo之间的连接  2)我是否总是必须进行本地连接,还是可以连接到neo4j服务器?  3)如果我可以连接到neo4j服务器,那么无论我在jupyter笔记本上运行的py2neo查询是否也要与neo4j数据库同步?

1 个答案:

答案 0 :(得分:0)

从错误的最后一行看,它似乎正在尝试在默认螺栓端口(即7687)上连接

我建议您使用这种格式而不是完整URI

graphdb = Graph(scheme="bolt", host="localhost", port=11004,
secure=True, auth=('neo4j', 'password'))