无法在Python中连接Neo4j推送数据

问题描述 投票:0回答:1

我有点疯狂地试图理解为什么我无法在 Python 中使用 CYPHER 将数据推送到我的 Neo4j 数据库。

我正在运行基本的测试代码只是为了看看是否可以推送数据。这是我的测试代码:

import logging
from neo4j import GraphDatabase

# Set up logging
logging.basicConfig(level=logging.DEBUG)  # Change the level to ERROR, WARNING, INFO, or DEBUG as needed
log = logging.getLogger("neo4j")

class Neo4jService:
    def __init__(self, uri, user, password):
        self._driver = GraphDatabase.driver(uri, auth=(user, password))
        
    def close(self):
        log.debug("Closing driver.")
        self._driver.close()
        
    def run_queries(self, queries):
        log.debug("Running queries.")
        with self._driver.session() as session:
            for query in queries:
                log.debug(f"Executing query: {query}")
                session.run(query)

try:
    # Initialize the Neo4j service
    URI = "neo4j+s://838f9df7.databases.neo4j.io"
    AUTH = ("neo4j", "my_password")

    log.info("Initializing driver.")
    with GraphDatabase.driver(URI, auth=AUTH) as driver:
        log.info("Verifying connectivity.")
        driver.verify_connectivity()

    summary = driver.execute_query(
        "MERGE (:Person {name: $name})",
        name="Alice",
        database_="neo4j",
    ).summary

    log.info(f"Created {summary.counters.nodes_created} nodes in {summary.result_available_after} ms.")

except Exception as e:
    log.error("An error occurred:", exc_info=True)

无论我做什么,我都会收到这样的错误:

neo4j.exceptions.ServiceUnavailable: Unable to retrieve routing information

我尝试通过将证书保存为文件并在我的代码中包含信任设置来手动告诉 Neo4j 信任该证书。但这没有用。我尝试过从 neo4j+s 切换到 Bolt 或仅 Neo4j。我已经更新了 neo4j 和 python。感觉调试了两天左右。无论我做什么,我的 Neo4j 数据库中都没有任何反应。感谢帮助!

python neo4j cypher
1个回答
0
投票

尝试在 uri 上使用“neo4j+ssc”,如下所示 URI =“neo4j+ssc://838f9df7.databases.neo4j.io”

© www.soinside.com 2019 - 2024. All rights reserved.