Python中无法连接Neo4j推送数据

cgvd09ve  于 11个月前  发布在  Python
关注(0)|答案(1)|浏览(201)

我有点疯狂地试图理解为什么我不能使用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数据库中都没有发生任何事情。感谢帮助!

kyvafyod

kyvafyod1#

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

相关问题