无法在python

时间:2016-07-06 22:26:58

标签: python-3.x neo4j cypher neo4j-python-driver

一直在尝试使用python运行查询neo4j数据库。 该代码适用于最简单的查询,但并非适用于所有查询。我没有得到任何异常,并且不了解日志文件的根本原因。

我的代码看起来像这样..

from neo4j.v1 import GraphDatabase, basic_auth

graph_url = "bolt://localhost:7687"
graph_username = "neo4j"
graph_password = "neo4j"

driver =GraphDatabase.driver(graph_url, auth=basic_auth(graph_username, graph_password))
session = driver.session()
query_simple="Create (enitity:n{name : 'john doe'})"
session.run(query_simple)

query = "LOAD CSV WITH HEADERS FROM 'http://data.neo4j.com/northwind/products.csv' AS row CREATE (n:Product) SET n = row n.unitPrice = toFloat(row.unitPrice), n.unitsInStock = toInt(row.unitsInStock), n.unitsOnOrder = toInt(row.unitsOnOrder), n.reorderLevel = toInt(row.reorderLevel), n.discontinued = (row.discontinued <> '0')"
session.run(query)

简单查询运行正常,但其他查询不运行。它是一个示例查询,适用于我本地主机上的neo4j gui

在调试日志文件中我得到了这两种错误日志:

2016-07-06 22:14:27.062 + 0000 ERROR [o.n.b.v.t.BoltProtocolV1]无法写入对驱动程序的响应

  

java.lang.NullPointerException at   org.neo4j.bolt.v1.transport.ChunkedOutput.ensure(ChunkedOutput.java:156)     在   org.neo4j.bolt.v1.transport.ChunkedOutput.writeShort(ChunkedOutput.java:90)     在   org.neo4j.bolt.v1.packstream.PackStream $ Packer.packStructHeader(PackStream.java:304)     在   org.neo4j.bolt.v1.messaging.PackStreamMessageFormatV1 $ Writer.handleFailureMessage(PackStreamMessageFormatV1.java:154)     在   org.neo4j.bolt.v1.messaging.msgprocess.MessageProcessingCallback.publishError(MessageProcessingCallback.java:48)     在   org.neo4j.bolt.v1.messaging.msgprocess.MessageProcessingCallback.completed(MessageProcessingCallback.java:98)     在   org.neo4j.bolt.v1.messaging.msgprocess.MessageProcessingCallback.completed(MessageProcessingCallback.java:31)     在   org.neo4j.bolt.v1.runtime.internal.SessionStateMachine.after(SessionStateMachine.java:823)     在   org.neo4j.bolt.v1.runtime.internal.SessionStateMachine.run(SessionStateMachine.java:655)     在   org.neo4j.bolt.v1.runtime.internal.concurrent.SessionWorkerFacade.lambda $运行$ 3(SessionWorkerFacade.java:68)     在   org.neo4j.bolt.v1.runtime.internal.concurrent.SessionWorker.execute(SessionWorker.java:116)     在   java.lang.Thread.run上的org.neo4j.bolt.v1.runtime.internal.concurrent.SessionWorker.run(SessionWorker.java:77)(Thread.java:745)

  

2016-07-06 20:52:20.588 + 0000 ERROR [o.n.b.t.SocketTransportHandler]   处理客户端连接时发生致命错误:连接   由peer重置连接由peer java.io.IOException重置:Connection   在sun.nio.ch.FileDispatcherImpl.read0(本机方法)上由peer重置     在sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)at   sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)at at   sun.nio.ch.IOUtil.read(IOUtil.java:192)at   sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)at at   io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:311)     在   io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:881)     在   io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:242)     在   io.netty.channel.nio.AbstractNioByteChannel $ NioByteUnsafe.read(AbstractNioByteChannel.java:119)     在   io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)     在   io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)     在   io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)     在io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)at   io.netty.util.concurrent.SingleThreadEventExecutor $ 2.run(SingleThreadEventExecutor.java:111)     在java.lang.Thread.run(Thread.java:745)

我在我的系统上使用neo4j的社区版,python版本3.5

提前致谢:)

1 个答案:

答案 0 :(得分:0)

您是否注意到文件conf/neo4j.conf中的以下部分?

# Determines if Cypher will allow using file URLs when loading data using
# `LOAD CSV`. Setting this value to `false` will cause Neo4j to fail `LOAD CSV`
# clauses that load data from the file system.
#dbms.security.allow_csv_import_from_file_urls=true

然而(在取消注释上面的行并重新启动neo4j之后),您可能会收到与解释内容有关的另一个错误:https://neo4j.com/developer/kb/explanation-of-error-load-csv-error-of-couldnt-load-the-external-resource/

您也可以尝试下载csv文件并将其保存到import目录中,然后使用:

LOAD CSV WITH HEADERS FROM 'file:///products.csv' AS row ...