Neo4j Python REST API

huangapple go评论52阅读模式
英文:

Neo4j Python REST API

问题

Query via Python REST-APi
Neo4j Python REST API
message: Invalid input: ':'
Neo4j Python REST API

Hello,
我正在尝试通过我的Python-Neo4j-API进行查询。
但是代码不起作用,导致出现上面的错误消息。
但是相同的查询在Neo4J桌面应用程序中可以工作。为什么它在Neo4j桌面应用程序中工作,但不通过我的API查询。为什么在参数前面有一个冒号是个问题?

我对Python和Neo4j都不太了解,请帮助。
致以亲切的问候。

尝试通过Python-Neo4j-RestAPI进行查询。

英文:

Query via Python REST-APi
Neo4j Python REST API
message: Invalid input: ':'
Neo4j Python REST API

Hello,
i am starting a query via my Python-Neo4j-Api.
But the code ist not working, resulting in the the error message above.
But the same query is working in the Neo4J Desktop App.
Why is it working in the Neo4j Desktop App, but not via my Api Query. Why is the : before param a Problem?

I am new to Python and Neo4j, please help.
King regards.

Trying to query via a Python-Neo4j-RestAPI.

答案1

得分: 0

我看到你一直在浏览器应用程序中使用数据库。所以以“:”前缀的命令,比如:params或:connect,都是浏览器命令,不是有效的Cypher查询语句。相反,在Python中,将参数作为session.run()函数或事务的第二个参数传递。然后在Cypher查询中使用变量替代。

params = {"name": "Tom Hanks"}
with driver.session as session:
    result = session.run("MATCH (p:person) WHERE p.name = $name RETURN p", params)

这样就可以正确传递参数并执行Cypher查询了。

英文:

I see that you have been working with the database though the browser application. So commands that are prefixed with ":" like :params or :connect are browser commands and is not valid cypher. Instead, in python pass your parameters as the second argument to your to your session.run() function or transaction. Then use variable substitution to in your cypher query.

params = {"name": "Tom Hanks" }
with driver.session as session:
    result = session.run ("MATCH (p:person) where p.name = $name return p", params)

答案2

得分: 0

以下是在neo4j python驱动程序中传递参数的语法。不幸的是,您不能在参数中使用标签或关系类型。如果您需要传递标签(例如Human:Moviestar),则可以在Python中使用字符串函数,就像这样:https://stackoverflow.com/questions/66824261/passing-parameters-in-neo4j-using-python

name = "汤姆·克鲁斯"
placeOfBirth = "纽约州锡拉丘兹,美国" 
query = "CREATE (n:Human:Moviestar { name: $name, placeOfBirth: $placeOfBirth})"
session = driver.session()
result = session.run(query, name=name, placeOfBirth=placeOfBirth)

注意:已将参数中的引号转义并将英文名称翻译为中文。

英文:

Below is the syntax on passing parameters in neo4j python driver. Unfortunately, you cannot use labels or relationship types in the parameter. If you need to pass labels (like Human:Moviestar) then you can use string function in python like this: https://stackoverflow.com/questions/66824261/passing-parameters-in-neo4j-using-python

name = "Tom Cruise"
placeOfBirth = "Syracuse, New York, United States" 
query = "Create (n:Human:Moviestar { name: $name, placeOfBirth: $placeOfBirth})"
session = driver.session()
result = session.run(query, name=name, placeOfBirth=placeOfBirth) 

huangapple
  • 本文由 发表于 2023年2月6日 18:21:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75360022.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定