SocketError:使用py2neo拒绝连接到远程服务器

时间:2015-01-29 21:18:47

标签: authentication py2neo

虽然这个问题在过去已经解决了几次,但我尝试了所有的建议,问题仍然存在,我希望有人会对此有所了解。

我的公司在远程ubuntu服务器上设置了neo4j(v2.1.6)图形数据库。 为了修改和更新服务器中的数据,我使用的是python包py2neo。

服务器的端点地址为http://fake-address.com/db/data,身份验证ID /密码为'fakeId'和'fakePassWord'。

为了访问远程数据库,在我的本地机器python终端中,

我尝试了以下内容:

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)")

不幸的是,上面的命令导致以下错误消息。

  /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

对于长错误消息感到抱歉,我非常感谢您的任何建议。

1 个答案:

答案 0 :(得分:0)

问题已经解决。问题必须出在py2neo中的身份验证中。使用最新版本的py2neo(2.0.4),连接正确。