我正在使用Py2neo包来查询位于服务器机器中的数据库。
我的代码段
from py2neo import Graph,authenticate
import time
from py2neo.packages.httpstream import http
http.socket_timeout = 9999
def dbConnect():
graph = Graph("http://192.xxx.xxx.xxx:7473/root/neo4j.graphdb")
print(graph)
#execute a cypher query
cypher()
return
def cypher():
start_time = time.time()
result = graph.cypher.execute("MATCH (n) RETURN COUNT(n)")
print(time.time - start_time)
return
if __name__ == '__main__':
dbConnect()
无法从机器获取数据,而是返回错误,
错误讯息:
<Graph uri=u'http://192.168.204.146:7473/root/neo4j.graphdb/'>
Traceback (most recent call last):
File "D:\Innominds\Collective[I]\Dev\Graph\Cypher_VS_Api.py", line 30, in <module>
dbConnect()
File "D:\Innominds\Collective[I]\Dev\Graph\Cypher_VS_Api.py", line 19, in dbConnect
cypher()
File "D:\Innominds\Collective[I]\Dev\Graph\Cypher_VS_Api.py", line 25, in cypher
result = graph.cypher.execute("MATCH (n) RETURN COUNT(n)")
File "C:\Python27\lib\site-packages\py2neo\core.py", line 661, in cypher
metadata = self.resource.metadata
File "C:\Python27\lib\site-packages\py2neo\core.py", line 213, in metadata
self.get()
File "C:\Python27\lib\site-packages\py2neo\core.py", line 258, in get
response = self.__base.get(headers=headers, redirect_limit=redirect_limit, **kwargs)
File "C:\Python27\lib\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 "C:\Python27\lib\site-packages\py2neo\packages\httpstream\http.py", line 943, in __get_or_head
return rq.submit(redirect_limit=redirect_limit, **kwargs)
File "C:\Python27\lib\site-packages\py2neo\packages\httpstream\http.py", line 433, in submit
http, rs = submit(self.method, uri, self.body, self.headers)
File "C:\Python27\lib\site-packages\py2neo\packages\httpstream\http.py", line 325, in submit
response = send("peer closed connection")
File "C:\Python27\lib\site-packages\py2neo\packages\httpstream\http.py", line 318, in send
return http.getresponse(**getresponse_args)
File "C:\Python27\lib\httplib.py", line 1074, in getresponse
response.begin()
File "C:\Python27\lib\httplib.py", line 415, in begin
version, status, reason = self._read_status()
File "C:\Python27\lib\httplib.py", line 379, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''
观察,错误消息中的第一行只是代码中的print语句,它将图形对象打印到控制台。并且,http import是一种谷歌知识。
为了从本地计算机访问服务器计算机中的图形数据库,需要进行哪些设置和更改。
答案 0 :(得分:0)
首先,您应该检查您的服务器是否可访问,以及是否可以在浏览器中打开Web界面。
您使用标准http
端口https
连接到7473
,并且网址错误。
http://192.xxx.xxx.xxx:7473/root/neo4j.graphdb
您应该尝试将http
与7474
或https
联系到7473
。图表网址应该看起来像http://server:port/db/data
。尝试:
http://192.xxx.xxx.xxx:7474/db/data
https://192.xxx.xxx.xxx:7473/db/data
此外,您不使用身份验证。你在服务器上禁用了它吗?