py2neo 引发 ConstraintViolation 错误,shell 不会
py2neo raises ConstraintViolation Error, shell does not
当我尝试在py2neo 中导入语句时出现ConstraintViolation 错误,但当我在neo4j 中直接导入时不会出现同样的错误shell。我在两者中都使用了完全相同的语句,在 py2neo 中我只是使用 graph.cypher.execute(...)。请注意,我已多次确保每个 ID 都是唯一的——没有重复值。
py2neo.cypher.error.schema.ConstraintViolation: Node 0 already exists with label Employee and property "ID"=[XXXX]
使用 py2neo,即使错误被调用并结束了程序,整个命令仍然 运行s 出来,就像在 neo4j shell 中一样填充图形。
问题: 我如何捕获错误以便我的其余导入语句可以正确 运行?我尝试捕获以下内容但没有成功:error.ConstraintViolation、error.schema.ConstraintViolation。
此外:导入在遇到那个很棒的错误后继续。但是,在 "continues" 打印后导入仍在继续。
try:
graph.cypher.execute(statement)
except ConstraintViolation as e:
# print(traceback.format_exec())
print "ConstraintViolation error"
print "continues"
您需要正确导入 ConstraintViolation 并捕获它:
from py2neo.cypher.error.schema import ConstraintViolation
import traceback
try:
# your cypher.execute() here
except ConstraintViolation as e:
# do whatever you want to do when the error occurs
# e.g. print the traceback of the error
print(traceback.format_exc())
当我尝试在py2neo 中导入语句时出现ConstraintViolation 错误,但当我在neo4j 中直接导入时不会出现同样的错误shell。我在两者中都使用了完全相同的语句,在 py2neo 中我只是使用 graph.cypher.execute(...)。请注意,我已多次确保每个 ID 都是唯一的——没有重复值。
py2neo.cypher.error.schema.ConstraintViolation: Node 0 already exists with label Employee and property "ID"=[XXXX]
使用 py2neo,即使错误被调用并结束了程序,整个命令仍然 运行s 出来,就像在 neo4j shell 中一样填充图形。
问题: 我如何捕获错误以便我的其余导入语句可以正确 运行?我尝试捕获以下内容但没有成功:error.ConstraintViolation、error.schema.ConstraintViolation。
此外:导入在遇到那个很棒的错误后继续。但是,在 "continues" 打印后导入仍在继续。
try:
graph.cypher.execute(statement)
except ConstraintViolation as e:
# print(traceback.format_exec())
print "ConstraintViolation error"
print "continues"
您需要正确导入 ConstraintViolation 并捕获它:
from py2neo.cypher.error.schema import ConstraintViolation
import traceback
try:
# your cypher.execute() here
except ConstraintViolation as e:
# do whatever you want to do when the error occurs
# e.g. print the traceback of the error
print(traceback.format_exc())