使用 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
此页面有帮助吗?