SocketError: Connection refused using py2neo to a remote server

雨燕双飞 提交于 2019-12-24 11:37:55

问题


While this issue has been addressed a couple of times in the past at SO and I tried all the suggestions, the problem still remains and I am hoping someone would shine a light on this.

My company set up a neo4j (v2.1.6) graph database at a remote ubuntu server. In order to modify and update data into the server, I am using a python package, py2neo.

The server's endpoint address is http://fake-address.com/db/data and the authentication Id/password are 'fakeId' and 'fakePassWord'.

In order to access the remote database, in my local machine python terminal,

I tried the following:

from py2neo import authenticate, Graph
authenticate("fake-address.com:80", "fakeId", "fakePassWord")
graph = Graph("http://fake-address.com:80/db/data/")
result = graph.cypher.execute("CREATE (a:Color)")

Unfortunately, the above command resulted in the following error message.

  /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/cypher/core.pyc in execute(self, statement, parameters, **kwparameters)
107         """
108         if self.transaction_uri:
--> 109             tx = CypherTransaction(self.transaction_uri)
110             tx.append(statement, parameters, **kwparameters)
111             results = tx.commit()

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/cypher/core.pyc in __init__(self, uri)
180         self.__commit = None
181         self.__finished = False
--> 182         self.graph = self.__begin.graph
183 
184     def __enter__(self):

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/core.pyc in graph(self)
211         :rtype: :class:`.Graph`
212         """
--> 213         return self.__service_root.graph
214 
215     @property

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/core.pyc in graph(self)
523         if self.__graph is None:
524             try:
--> 525                 uri = self.resource.metadata["data"]
526             except KeyError:
527                 if "authentication" in self.resource.metadata:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/core.pyc in metadata(self)
226             if self.__initial_metadata is not None:
227                 return self.__initial_metadata
--> 228             self.get()
229         return self.__last_get_response.content
230 

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/core.pyc in get(self, headers, redirect_limit, **kwargs)
271         kwargs.update(cache=True)
272         try:
   --> 273             response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
274         except (ClientError, ServerError) as error:
275             if error.status_code == UNAUTHORIZED:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/packages/httpstream/http.pyc in get(self, if_modified_since, headers, redirect_limit, **kwargs)
964             object from which content can be read
965         """
--> 966         return self.__get_or_head("GET", if_modified_since, headers, redirect_limit, **kwargs)
967 
968     def put(self, body=None, headers=None, **kwargs):

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/packages/httpstream/http.pyc in __get_or_head(self, method, if_modified_since, headers, redirect_limit, **kwargs)
941             headers["If-Modified-Since"] = formatdate(datetime_to_timestamp(if_modified_since), usegmt=True)
942         rq = Request(method, self.uri, None, headers)
--> 943         return rq.submit(redirect_limit=redirect_limit, **kwargs)
944 
945     def head(self, if_modified_since=None, headers=None, redirect_limit=5, **kwargs):

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/packages/httpstream/http.pyc in submit(self, redirect_limit, **response_kwargs)
431         uri = self.uri
432         while True:
--> 433             http, rs = submit(self.method, uri, self.body, self.headers)
434             status_class = rs.status // 100
435             if status_class == 3:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/py2neo/packages/httpstream/http.pyc in submit(method, uri, body, headers)
360                                       host_port=uri.host_port)
361         else:
--> 362             raise SocketError(code, description, host_port=uri.host_port)
363     else:
364         return http, response

SocketError: Connection refused

Sorry about the long error message and I greatly appreciate any suggestions.


回答1:


The issue has been resolved. The problem must have been in the authentication in py2neo. With the newest version of py2neo (2.0.4), the connection was properly made.



来源:https://stackoverflow.com/questions/28224779/socketerror-connection-refused-using-py2neo-to-a-remote-server

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