Neo4J与Py2neo:未经授权的错误HTTPS

我有Neo4J运行在一个Docker容器中,其中我已经将内部容器端口7473和7687映射到它们各自的主机端口7473和7687,7474是暴露的但未映射。

关于networking的Neo4J服务器configuration。

# Bolt connector dbms.connector.bolt.enabled=true #dbms.connector.bolt.tls_level=OPTIONAL dbms.connector.bolt.listen_address=0.0.0.0:7687 # HTTP Connector. There must be exactly one HTTP connector. dbms.connector.http.enabled=true dbms.connector.http.listen_address=0.0.0.0:7474 # HTTPS Connector. There can be zero or one HTTPS connectors. dbms.connector.https.enabled=true dbms.connector.https.listen_address=0.0.0.0:7473 

我能够通过浏览器login到Neo4J的web客户端,并更改默认密码。

关于Python代码,我在这里创build客户端。

 self.client = py2neo.Graph(host =ip_address, username=username, password=password, secure =use_secure, bolt =use_bolt) 

只要我执行这样的查询。

 node = Node("FooBar", foo="bar") self.client.create(node) 

我得到以下未经授权的例外。

 py2neo.database.status.Unauthorized: https://localhost:7473/db/data/ 

任何想法为什么这可能会发生?

解决scheme是调用库提供的单独的身份validation方法,如下所示:

 auth_port = str(self._PORT_HTTPS if use_secure else self._PORT_HTTP) py2neo.authenticate(":".join([ip_address, auth_port]), username, password) 

我花了一段时间才得到这个,因为起初,我认为authentication是在构造函数中自动完成的,然后我无法使authentication方法运行,因为我使用的是螺栓端口。