Service unavailable error using neo4j driver for python

元气小坏坏 提交于 2019-12-11 15:04:03

问题


I am new to neo4j and trying to execute the demo project(Movie search) provided in neo4j website. While doing so I am getting an error to instantiate neo4j server from python. Alternatively, I am able to up and run neo4j server externally and use it. Please find the python code snippet and error details -

import os
from json import dumps
from flask import Flask, g, Response, request
from neo4j.v1 import GraphDatabase, basic_auth
app = Flask(__name__, static_url_path='/static/')
password = os.getenv("NEO4J_PASSWORD")
driver = GraphDatabase.driver('bolt://localhost',auth=basic_auth("neo4j", password))
.
.

when I run this above mention code I get the following error message:

Traceback (most recent call last):
File "movies.py", line 12, in <module>
driver = GraphDatabase.driver('bolt://localhost',auth=basic_auth("neo4j", password))
File "C:\Users\611593250\AppData\Local\Programs\Python\Python36-32\lib\site-packages\neo4j\v1\api.py", line 124, in driver
return driver_class(uri, **config)
File "C:\Users\611593250\AppData\Local\Programs\Python\Python36-32\lib\site-packages\neo4j\v1\direct.py", line 65, in __init__
pool.release(pool.acquire())
File "C:\Users\611593250\AppData\Local\Programs\Python\Python36-32\lib\site-packages\neo4j\v1\direct.py", line 44, in acquire
raise ServiceUnavailable("Cannot acquire connection to {!r}".format(self.address))
neo4j.exceptions.ServiceUnavailable: Cannot acquire connection to Address(host='localhost', port=7687)

Please advice. Thanks in advance!


回答1:


You have to add your bolt port when defining the bolt url like below:

import os
from json import dumps
from flask import Flask, g, Response, request
from neo4j.v1 import GraphDatabase, basic_auth
app = Flask(__name__, static_url_path='/static/')
password = os.getenv("NEO4J_PASSWORD")
driver = GraphDatabase.driver('bolt://localhost:7687',auth=basic_auth("neo4j", password))
print driver

hope this helps!




回答2:


I think the problem was with neo4j local server instance. When I restarted the local server, the same code worked.. I guess. Because, right now I am getting some different error. Thanks for your response!



来源:https://stackoverflow.com/questions/47133423/service-unavailable-error-using-neo4j-driver-for-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!