py2neo.neo4j.GraphDatabaseService.node(id)引发ClientError(e)

时间:2014-06-20 12:12:09

标签: py2neo

我认为对于经验丰富的py2neo用户来说这可能是显而易见的,但是因为我是新手,所以我无法克服它。我正在尝试关注py2neo在线doc:http://book.py2neo.org/en/latest/graphs_nodes_relationships/,但我能够使用'Node'方法来返回从 GraphDatabaseService.create,但当我使用GraphDatabaseService.node检索节点时,所有预期的Node方法都停止工作,我已经使用Node.len方法将其缩小到下面的示例。

提前感谢任何有用的见解。

布鲁斯

我的环境: Windows 7专业 pycharm 3.4 py2neo 1.6.4 python2.7.5

以下是代码:

from py2neo import node, neo4j

db = neo4j.GraphDatabaseService()
db.clear()
a, = db.create(node({'name': ['a']}))
a.add_labels('Label')
b = db.node(a._id)
print db.neo4j_version
print b, type(b)
print "There is %s node in db" % db.order
print len(b)

以下是输出:

C:\Python27\python.exe C:/Users/you_zhang/PycharmProjects/py2neo/ex11.py
(2, 0, 3, u'')
(10) <class 'py2neo.neo4j.Node'>
There is 1 node in db
Traceback (most recent call last):
  File "C:/Users/you_zhang/PycharmProjects/py2neo/ex11.py", line 11, in <module>
    print len(b)
  File "C:\Users\you_zhang\AppData\Roaming\Python\Python27\site-packages\py2neo\neo4j.py", line 1339, in __len__
    return len(self.get_properties())
  File "C:\Users\you_zhang\AppData\Roaming\Python\Python27\site-packages\py2neo\neo4j.py", line 1398, in get_properties
    self._properties = assembled(self._properties_resource._get()) or {}
  File "C:\Users\you_zhang\AppData\Roaming\Python\Python27\site-packages\py2neo\neo4j.py", line 1349, in _properties_resource
    return self._subresource("properties")
  File "C:\Users\you_zhang\AppData\Roaming\Python\Python27\site-packages\py2neo\neo4j.py", line 403, in _subresource
    uri = URI(self.__metadata__[key])
  File "C:\Users\you_zhang\AppData\Roaming\Python\Python27\site-packages\py2neo\neo4j.py", line 338, in __metadata__
    self.refresh()
  File "C:\Users\you_zhang\AppData\Roaming\Python\Python27\site-packages\py2neo\neo4j.py", line 360, in refresh
    self._metadata = ResourceMetadata(self._get().content)
  File "C:\Users\you_zhang\AppData\Roaming\Python\Python27\site-packages\py2neo\neo4j.py", line 367, in _get
    raise ClientError(e)
py2neo.exceptions.ClientError: Not Found

1 个答案:

答案 0 :(得分:0)

您的完全代码段适用于我(OS X,neo4j 2.1.2)。不应该有任何问题。您是否尝试安装最新版本的neo4j并在新鲜且未受影响的数据库上运行代码?我在损坏的数据库中遇到了不一致。

您是否尝试使用.find()加载节点?

result = db.find('Label')
for n in result:
    print(n)