我正在使用GrapheneDB,Tornado,py2neo在Heroku上运行一个应用程序。
我正在尝试使用py2neo的Cypher交易。
我可以在本地运行:
graphenedb_url = os.environ.get("GRAPHENEDB_URL", "http://localhost:7474/")
service_root = neo4j.ServiceRoot(URI(graphenedb_url).resolve("/"))
graph_db = service_root.graph_db
session = cypher.Session()
但是当我部署到Heroku时,我得到了:
2014-10-06T20:33:34.626356+00:00 app[web.1]: File "main.py", line 33, in <module>
2014-10-06T20:33:34.626364+00:00 app[web.1]: session = cypher.Session()
2014-10-06T20:33:34.626367+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/cypher.py", line 127, in __init__
2014-10-06T20:33:34.626435+00:00 app[web.1]: self._graph_db = self._service_root.graph_db
2014-10-06T20:33:34.626456+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/neo4j.py", line 462, in graph_db
2014-10-06T20:33:34.626550+00:00 app[web.1]: return GraphDatabaseService.get_instance(self.__metadata__["data"])
2014-10-06T20:33:34.626571+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/neo4j.py", line 338, in __metadata__
2014-10-06T20:33:34.626641+00:00 app[web.1]: self.refresh()
2014-10-06T20:33:34.626662+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/neo4j.py", line 360, in refresh
2014-10-06T20:33:34.626732+00:00 app[web.1]: self._metadata = ResourceMetadata(self._get().content)
2014-10-06T20:33:34.626756+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/neo4j.py", line 365, in _get
2014-10-06T20:33:34.626838+00:00 app[web.1]: product=self._product)
2014-10-06T20:33:34.626842+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 803, in get
2014-10-06T20:33:34.627276+00:00 app[web.1]: return rq.submit(redirect_limit=redirect_limit, **kwargs)
2014-10-06T20:33:34.627279+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 388, in submit
2014-10-06T20:33:34.627281+00:00 app[web.1]: http, rs = submit(self.method, uri, self.body, headers)
2014-10-06T20:33:34.627282+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 328, in submit
2014-10-06T20:33:34.627288+00:00 app[web.1]: raise SocketError(code, description, host_port=uri.host_port)
2014-10-06T20:33:34.627290+00:00 app[web.1]: py2neo.packages.httpstream.http.SocketError: Connection refused
2014-10-06T20:33:34.626336+00:00 app[web.1]: Traceback (most recent call last):
2014-10-06T20:33:35.495790+00:00 heroku[web.1]: Process exited with status 1
2014-10-06T20:33:35.505975+00:00 heroku[web.1]: State changed from starting to crashed
我也尝试过:
session = cypher.Session(URI(graphenedb_url).resolve("/"))
但这甚至不适用于本地。我试过浏览Graphene Docs,但没有运气。
有什么建议吗?
更新: 如果我这样做:
session = cypher.Session(os.environ.get("GRAPHENEDB_URL"))
tx = session.create_transaction()
tx.append("MATCH n RETURN n")
results = tx.execute()
for r in results[0]:
r.values[0]
我明白了:
Node('http://localhost:0/db/data/node/40')
Node('http://localhost:0/db/data/node/41')
Node('http://localhost:0/db/data/node/42')
我猜这个端口应该是7474而不是0?
或者不应该是Node('GRAPHENEDB_URI/db/data/node/40')
而不是localhost?
答案 0 :(得分:3)
这是bug in Neo4j。事务提交URL的问题在2.1.5中已修复,但节点的URL仍然是错误的。
我已更新此问题,并已重新打开。
AFAIK只影响事务端点,因此REST接口的其他端点应该没问题。
我能想到的唯一解决方法是在Py2neo中使用URL重写,documented here。
我希望很快就能解决,我真的很抱歉,我没有其他选择让你解决这个问题。