gpt4 book ai didi

python - 如何使用 python Rest api 在 neo4j 中获取密码查询的响应

转载 作者:太空宇宙 更新时间:2023-11-03 14:21:02 25 4
gpt4 key购买 nike

我正在使用 Python 访问 neo4j 并创建节点。在创建节点之前,我想检查它是否存在。我运行这个查询:

          "query" : "match (PPnode:Node) return PPnode"

并使用requests库的方法:

           r.text

我得到一个字符串,其中包含我的 POST 请求的响应。我的问题是是否有一种更“优雅”的方法来使用 python 和 rest api 检查是否存在具有特定名称的现有节点。

这是我的代码:

   import requests
import json
import csv

headers = {'content-type': 'application/json'}
url = "http://localhost:7474/db/data/cypher"


fparts = open('FOC.csv')
csv_pseudo = csv.reader(fparts)


for row in csv_pseudo:

# query to check if node exists
checkNode = {"query" : "match (PPnode:Node) return PPnode"}
mkr =requests.post(url, data=json.dumps(checkNode), headers=headers)

谢谢季米特里斯

最佳答案

我认为您在这里工作可能比您需要的更努力。有一个图书馆叫py2neo这将更简单地做你想做的事。如果您正在使用它,您可以获得实际对象而不是原始 JSON,这可能更容易处理:

来自 the documentation on how to run Cypher queries :

from py2neo import Graph
graph = Graph("http://nifty-site:1138/db/data/")
results = graph.cypher.execute("match (PPnode:Node) return PPnode")

for r in results:
# get the node you return in your query
ppNode = r[0]
# get the properties of your node
props = ppNode.get_properties()
# Do nifty stuff with properties, not JSON.

关于python - 如何使用 python Rest api 在 neo4j 中获取密码查询的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27840751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com