Python py2neo引发ConstraintViolation错误,shell未引发
当我在py2neo中尝试import语句时,会出现ConstraintViolation错误,但当我直接在neo4j的shell中导入时,不会出现相同的错误。我在这两种语言中使用的是相同的语句,在py2neo中我只使用graph.cypher.execute(…)。注意,我多次确保每个ID都是唯一的——没有重复的值Python py2neo引发ConstraintViolation错误,shell未引发,python,neo4j,py2neo,Python,Neo4j,Py2neo,当我在py2neo中尝试import语句时,会出现ConstraintViolation错误,但当我直接在neo4j的shell中导入时,不会出现相同的错误。我在这两种语言中使用的是相同的语句,在py2neo中我只使用graph.cypher.execute(…)。注意,我多次确保每个ID都是唯一的——没有重复的值 py2neo.cypher.error.schema.ConstraintViolation: Node 0 already exists with label Employee a
py2neo.cypher.error.schema.ConstraintViolation: Node 0 already exists with label Employee and property "ID"=[XXXX]
对于py2neo,即使调用了错误并结束了程序,整个命令仍然会运行,填充图形就像在neo4j shell中一样
问题:如何捕获错误,以便其余的导入语句能够正常运行?我尝试捕获以下内容但未成功:error.ConstraintViolation、error.schema.ConstraintViolation
此外:在遇到该错误后,导入将继续,该错误非常严重。但是,在“继续”打印之后,导入将继续
您需要正确导入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())
您需要正确导入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())
这导致了以下问题:AttributeError:“module”对象没有属性“format\u exec”
traceback
在Python2.7和3.4()中有一个format\u exc()。导入可能有问题?这导致了以下问题:AttributeError:“module”对象没有属性“format\u exec”traceback
在Python 2.7和3.4()中有一个format\u exc()。也许是进口产品出了问题?