使用 Python 1.7.x 驱动程序与 Neo4j 4.0
在撰写本文时,适用于 Neo4j 4.0 的 Bolt Python 驱动程序尚未发布。v4 Python 驱动程序将在 2020 年第一季度末发布。
那么,如何使用 1.7.x 代 Python 驱动程序连接到 Neo4j 4.0 呢?
最重要的是要记住,在使用 1.7.x 代驱动程序连接到 4.0.x 数据库时,必须禁用加密流量。
以下是操作方法
from neo4j import GraphDatabase
uri = "bolt://localhost:7687"
driver = GraphDatabase.driver(uri, auth=("neo4j", "letmein"), encrypted=False)
def print_movies_acted_in(tx, name):
for record in tx.run("MATCH (a:Person)-[:ACTED_IN]->(m) "
"WHERE a.name = $name "
"RETURN m.title", name=name):
print(record["m.title"])
with driver.session() as session:
session.read_transaction(print_movies_acted_in, "Keanu Reeves")
请注意,通过 **Driver** 构造函数设置的 **encrypted** 配置。如果 TLS 可用,则默认为 True。
driver = GraphDatabase.driver(uri, auth=("neo4j", "letmein"), encrypted=False)
有关 **Driver** 对象的更多详细信息,请参阅以下链接 -
如预期的那样,上述代码的结果将是
The Matrix Revolutions The Matrix Reloaded Something's Gotta Give The Devil's Advocate The Replacements Johnny Mnemonic The Matrix
此页面对您有帮助吗?