如何在python中将参数传递给apoc.export.csv.query?

How to pass a parameter to apoc.export.csv.query in python?

我正在尝试将数据从 CSV 文件发送到 python 中的 apoc 查询。 我的查询如下所示:

"""

            CALL apoc.export.csv.query("MATCH(n:Entity{EntityType:'Configuration_Item', Name:$CI_name}) --(ev:Event)--(c:Common)
            optional match (c)--(ev_c:Event)--(en:Entity)
            where en.EntityType='Change' or en.EntityType='Interaction'
            with  en.EntityType as ent,ev_c.Activity as act, en.IDraw as ID, ev.Start as date
            order by ev.Start where not ent='null'
            return collect(act), ID, ent", "results.csv",{stream:true, params:{CI_Name:$CI_name}})
           """

发送数据的Python代码如下:

with open ('CI.csv','r') as first_file:
csv_f = csv.DictReader(first_file)
for row in csv_f:
    counter(row["n.Name"])

但是,我收到以下错误

提高CypherError.hydrate(*元数据) neobolt.exceptions.ClientError:预期参数:CI_name

你能帮我解决这个问题吗?

谢谢!

我通过如下更改查询解决了问题:

 query="""  

            CALL apoc.export.csv.query("MATCH(n:Entity{EntityType:'Configuration_Item'}) --(ev:Event)--(c:Common)
            where n.Name='%s'
            optional match (c)--(ev_c:Event)--(en:Entity)
            where en.EntityType='Change' or en.EntityType='Interaction'
            with  en.EntityType as ent,ev_c.Activity as act, en.IDraw as ID, ev.Start as date
            order by ev.Start where not ent='null'
            return collect(act), ID, ent", "/results_test.csv",{stream:true})
            """
query = query % (CI_name)
graph.run(query)             

来源:https://pythonpedia.com/en/tutorial/5841/neo4j-and-cypher-using-py2neo