简体   繁体   English

带有Py2neo的Neo4J:未经授权的错误HTTPS

[英]Neo4J with Py2neo: Unauthorized error HTTPS

I have Neo4J running on a Docker container in which I have mapped the internal container ports 7473 and 7687 to their respective host ports 7473 and 7687, 7474 is exposed but not mapped. 我在Docker容器上运行Neo4J ,在其中我已将内部容器端口7473和7687映射到它们各自的主机端口7473和7687,其中7474是公开的但未映射。

The Neo4J server configuration regarding network. 关于网络的Neo4J服务器配置。

# 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

I was able to login to Neo4J's webclient through the browser and change the default password. 我能够通过浏览器登录Neo4J的Web客户端并更改默认密码。

Regarding the Python code here's the line where I create the client. 关于Python代码,这是我创建客户端的行。

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

As soon as I execute a query like this one. 一旦执行这样的查询。

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

I get the following Unauthorized exception. 我收到以下未授权的异常。

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

Any idea on why this may be happening? 知道为什么会这样吗?

The solution was to call a separate authentication method provided by the library like this: 解决方案是调用库提供的单独的身份验证方法,如下所示:

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

It took me a while to get to this because at first, I thought the authentication was done automatically in the constructor and then I wasn't able to make the authentication method run because I was using the bolt port. 我花了一些时间才能做到这一点,因为起初,我认为身份验证是在构造函数中自动完成的,然后由于使用螺栓端口,所以我无法使身份验证方法运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM