【问题标题】:SocketError: Connection refused using py2neo to a remote serverSocketError:使用 py2neo 拒绝连接到远程服务器
【发布时间】:2015-01-29 21:18:47
【问题描述】:

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

我的公司在远程 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

对于冗长的错误信息,我深表歉意,非常感谢任何建议。

【问题讨论】:

  • 您确定服务器在端口 80 上运行吗?默认端口是7474。看来python根本无法建立tcp连接。你能通过你的网络浏览器访问fake-address.com:80/db/data(没有配置任何代理)吗?您可以看到在 conf/neo4j-server.properties 中配置的端口。属性行如下所示:org.neo4j.server.webserver.port=7474 用于默认端口。
  • 是的,我与公司确认,服务器在 80 端口上运行。为了安全起见,我尝试使用 7474,但它也不起作用。另外,我可以在我的网络浏览器中访问 fake-address.com:80/db/data/ 就好了。这让我很困惑。
  • 当您在终端 'telnet fake-address.com 80' 中键入以下内容时,您是否已连接?打印出来的 IP 地址是否符合您的预期?想知道您的浏览器中是否设置了代理服务器。
  • OP - 正如 Ryan 所说,这是一个与 neo4j 无关的网络问题。还要检查您的主机可能阻止流量的任何防火墙配置。 telnet 检查也是个好主意。
  • 请尝试使用'watch',它会打印出来自httpstream的调试信息。添加到您的进口“从 py2neo 进口手表”。然后在你提出任何请求之前调用'watch("httpstream")'。你应该看到 py2neo 连接到哪个特定的 IP 和端口。

标签: authentication py2neo


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-22
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多