我已经设置了neo4j在docker中运行,并公开了http和bolt端口(7474,7687)。
这是我使用的设置:
docker run \
--name testneo4j \
-p7474:7474 -p7687:7687 \
-d \
-v `pwd`/neo4j/data:/data \
-v `pwd`/neo4j/logs:/logs \
-v `pwd`/import:/var/lib/neo4j/import \
-v `pwd`/neo4j/plugins:/plugins \
--env NEO4J_AUTH=neo4j/XXXXXXX \
我现在尝试使用Python连接到图表数据库
使用py2neo
库工作正常:
In [1]: from py2neo import Graph
In [2]: graph=Graph('bolt://localhost:7687',user="neo4j", password="XXXXXXX")
...: graph.run('MATCH(x) RETURN COUNT(x)')
COUNT(x)
----------
0
但是当我使用neo4j
模块时:
from neo4j import GraphDatabase, TRUST_ALL_CERTIFICATES
trust=TRUST_ALL_CERTIFICATES
neo4j_user="neo4j"
neo4j_passwd="XXXXXXX"
uri="bolt://localhost:7687"
driver = GraphDatabase.driver(uri,
auth=(neo4j_user, neo4j_passwd),
encrypted=False, trust=trust)
我得到这个错误:
File ~/local/anaconda3/lib/python3.8/site-packages/neo4j/__init__.py:120, in GraphDatabase.driver(cls, uri, **config)
114 @classmethod
115 def driver(cls, uri, **config):
116 """ Create a :class:`.Driver` object. Calling this method provides
117 identical functionality to constructing a :class:`.Driver` or
118 :class:`.Driver` subclass instance directly.
119 """
--> 120 return Driver(uri, **config)
File ~/local/anaconda3/lib/python3.8/site-packages/neo4j/__init__.py:161, in Driver.__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)
File ~/local/anaconda3/lib/python3.8/site-packages/neo4j/__init__.py:235, in DirectDriver.__new__(cls, uri, **config)
232 return connect(address, **dict(config, **kwargs))
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"])
File ~/local/anaconda3/lib/python3.8/site-packages/neobolt/direct.py:715, in ConnectionPool.acquire(self, access_mode)
714 def acquire(self, access_mode=None):
--> 715 return self.acquire_direct(self.address)
File ~/local/anaconda3/lib/python3.8/site-packages/neobolt/direct.py:608, in AbstractConnectionPool.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)
File ~/local/anaconda3/lib/python3.8/site-packages/neo4j/__init__.py:232, in DirectDriver.__new__.<locals>.connector(address, **kwargs)
231 def connector(address, **kwargs):
--> 232 return connect(address, **dict(config, **kwargs))
File ~/local/anaconda3/lib/python3.8/site-packages/neobolt/direct.py:972, in connect(address, **config)
970 raise ServiceUnavailable("Failed to resolve addresses for %s" % address)
971 else:
--> 972 raise last_error
File ~/local/anaconda3/lib/python3.8/site-packages/neobolt/direct.py:964, in connect(address, **config)
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:
966 last_error = error
File ~/local/anaconda3/lib/python3.8/site-packages/neobolt/direct.py:920, in _handshake(s, resolved_address, der_encoded_server_certificate, **config)
918 if agreed_version == 0:
919 log_debug("[#%04X] C: <CLOSE>", local_port)
--> 920 s.shutdown(SHUT_RDWR)
921 s.close()
922 elif agreed_version in (1, 2):
OSError: [Errno 57] Socket is not connected
有人知道为什么前者有效而后者无效吗?
2条答案
按热度按时间ttisahbt1#
您使用的密码不同。
4uqofj5v2#
原来问题是我使用的是旧版本的Neo4J库(1. 7. 6)。我对5. 5版本做了一个
pip install neo4j --upgrade
,我不再得到任何错误。