我在VS代码中连接到我的Neo4j数据库时遇到了困难。
我从Neo4J文档中给出的模板代码开始:
from neo4j import GraphDatabase
import logging
from neo4j.exceptions import ServiceUnavailable
class Neo4jConnection:
def __init__(self, uri, user, pwd):
self.__uri = uri
self.__user = user
self.__pwd = pwd
self.__driver = None
try:
self.__driver = GraphDatabase.driver(self.__uri, auth=(self.__user, self.__pwd))
except Exception as e:
print("Failed to create the driver:", e)
def close(self):
if self.__driver is not None:
self.__driver.close()
def query(self, query, db=None):
assert self.__driver is not None, "Driver not initialized!"
session = None
response = None
try:
session = self.__driver.session(database=db) if db is not None else self.__driver.session()
response = list(session.run(query))
except Exception as e:
print("Query failed:", e)
finally:
if session is not None:
session.close()
return response
然后我连接到我的数据库:
conn = Neo4jConnection(uri="neo4j+s://7022d007.databases.neo4j.io", user="neo4j", pwd="****")
然后,我尝试调用neo4j来运行数据库中的任务:
query_string = '''
CALL db.schema.visualization()
'''
conn.query(query_string, db='MARA')
然后失败,并给出错误:无法检索路由信息查询失败:无法检索路由信息
1条答案
按热度按时间lqfhib0f1#
这可能是由于证书错误造成的。在将证书更改为自签名的SSL后,它对我起作用了。您可以尝试使用neo4j+ssc://{IP_ADDRESS}:{PORT}作为到数据库的链接。