[英]Neo4J with Py2neo: Unauthorized error HTTPS
我在Docker容器上運行Neo4J ,在其中我已將內部容器端口7473和7687映射到它們各自的主機端口7473和7687,其中7474是公開的但未映射。
關於網絡的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
我能夠通過瀏覽器登錄Neo4J的Web客戶端並更改默認密碼。
關於Python代碼,這是我創建客戶端的行。
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/
知道為什么會這樣嗎?
解決方案是調用庫提供的單獨的身份驗證方法,如下所示:
auth_port = str(self._PORT_HTTPS if use_secure else self._PORT_HTTP)
py2neo.authenticate(":".join([ip_address, auth_port]), username, password)
我花了一些時間才能做到這一點,因為起初,我認為身份驗證是在構造函數中自動完成的,然后由於使用螺栓端口,所以我無法使身份驗證方法運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.