Python py2neo SocketError: Connection Refused

非 Y 不嫁゛ 提交于 2019-12-25 04:15:28

问题


I'm trying to follow along to this neo4j tutorial and I'm having a problem connecting to the API. Here's my traceback:

>>> graph.delete_all()

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 748,    in     delete_all
 statement = StartOrMatch(self).relationship("r", "*").string + "DELETE r"
 File "/usr/local/lib/python2.7/site-packages/py2neo/cypher/util.py", line 45, in string
if self.graph.supports_start_clause:
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 1105, in    supports_start_clause
return self.neo4j_version < (2, 2)
 File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 964, in    neo4j_version
return version_tuple(self.resource.metadata["neo4j_version"])
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 213, in metadata
self.get()
File "/usr/local/lib/python2.7/site-packages/py2neo/core.py", line 258, in get
response = self.__base.get(headers=headers, redirect_limit=redirect_limit,   **kwargs)
File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 966, in get
return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs)
File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 943, in __get_or_head
return rq.submit(redirect_limit=redirect_limit, **kwargs)
File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 433, in submit
http, rs = submit(self.method, uri, self.body, self.headers)
File "/usr/local/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 362, in submit
raise SocketError(code, description, host_port=uri.host_port)
py2neo.packages.httpstream.http.SocketError: Connection refused

I'm new to networking/socket connections, so a human-readable explanation of what's going on would be very helpful.


回答1:


You don't show your connection code (the Graph constructor) or mention about your setup but the usual causes of this error are (1) the server is not running, (2) the client is connecting to the wrong machine or port or (3) there is a firewall in between client and server, blocking access.

I suggest you try to connect to the server from command line, using cURL or some similar tool, then make sure your Python code attaches to the same location.




回答2:


I had this error because I had specified the IP address in the .properties file but I was using localhost to connect. Once I used the IP address in both places it worked.

In /etc/neo4j/neo4j-server.properties

org.neo4j.server.webserver.address=1.2.3.4

API url:

http://neo4j:mypassword@1.2.3.4:7474/db/data/



来源:https://stackoverflow.com/questions/32783174/python-py2neo-socketerror-connection-refused

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