neo4j 'Session'对象没有'session'属性

hjzp0vay  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(232)

我收到错误

这是我的代码块(简化了,但仍显示错误)

import neo4j
import sys
import uuid

from neo4j import GraphDatabase

def create_population_point(tx, _point, _uuid, _tl, _tr, _ll, _lr, _band):
    print("Add a record block  A")
    tx.run("CREATE (n:Population_Point 
    {point:$point,uuid:$uuid,TL:$tl,TR:$tr,BL:$bl,BR:$br,Band_1:$band}),"
          "point=_point,uuid=_uuid,tl=_tl,tr=_tr,ll=_ll,lr=_lr,band=_band")

def main():
uri = "neo4j://localhost:7687"
username = "neo4j"
password = "P@ssword2"

databaseConnection = GraphDatabase.driver(uri, auth=(username, password))
databaseSession = databaseConnection.session()
print("Connection established")
print("Variables assigned values")
_point = "D007_S001_T001"
_uuid = uuid.uuid4()
_tl = "28.27291"
_tr = "-81.65765"
_ll = "28.27291"
_lr = "-81.65765"
_band = "455"
print("Ready to execute")
with databaseSession.session() as session:
    result = session.write_transaction(create_population_point, _point, _uuid, _tl, _tr, _ll, 
   _lr, _band)
databaseConnection.close()
print("Connection closed")

if __name__ == "__main__":
    main()

这是引发错误的行
将databaseSession.session()作为会话:
运行Python 3.10.4

envsm3lx

envsm3lx1#

首先您创建

databaseSession = databaseConnection.session()

然后使用

with databaseSession.session() as session:

所以最后你试着用

databaseConnection.session().session()

这是错误的。
您可以直接使用

result = databaseSession.write_transaction(..)

或在中使用databaseConnection而不是databaseSession

with databaseConnection.session() as session:
     result = session.write_transaction(..)

(and删除databaseSession = databaseConnection.session(),因为您不使用它)

相关问题