tx().commit() 在 python gremlin 中不起作用

问题描述 投票:0回答:2

在Python代码中,我试图从janusgraph中删除顶点并随后提交。但代码 g.tx().commit() 返回 - “exceptions.AttributeError:'GraphTraversalSource'对象没有属性'tx'”。 我是否缺少任何进口产品。请建议

我尝试过没有提交,但顶点只是停留在那里,而没有从代码中返回任何错误

使用 gremlin console 时提交工作正常。从代码中观察到问题

g.tx().commit()

exceptions.AttributeError:“GraphTraversalSource”对象没有属性“tx”。

python-2.7 gremlin janusgraph
2个回答
2
投票

gremlinpython 是一种 Gremlin 语言变体,它将 Gremlin 转换为字节码并将其提交到远程服务器执行。一旦到达服务器,事务就被认为是“受管理的”,因为每个请求都会自动启动一个事务,然后当请求过程完成时,服务器要么在成功的情况下提交事务,要么在失败的情况下回滚事务。正如您所发现的,您不能(也不需要)直接从 gremlinpython 调用

g.tx()

请考虑阅读 TinkerPop 简介 文档以获取更多信息。


0
投票
from gremlin_python import statics

从 gremlin_python.struct.graph 导入图 从 gremlin_python.driver.driver_remote_connection 导入 DriverRemoteConnection

定义JanusGraph服务器信息

JANUSGRAPH_SERVER =“ws://.:8182/gremlin”

创建 JanusGraph 图实例

图=图()

连接到 JanusGraph 服务器

连接= DriverRemoteConnection(JANUSGRAPH_SERVER,“g”)

创建一个遍历对象用于与图交互

尝试: g = graph.traversal().withRemote(连接) 打印('已连接') 除了异常 e: print('连接未建立:', str(e))

开始新交易

尝试: #g.tx().open() print('交易开始')

# Add a vertex
vertex = g.addV('Country').property('name', 'India').next()
print(f'Added vertex with id: {vertex.id}')

# Commit the transaction
#g.tx().commit()
print('Transaction committed')

例外情况为 e: print('错误:', str(e))

关闭连接

连接.close()

我遇到了同样的错误unpack require a buffer of 4 bytes 注释掉 tx.commit() 后

© www.soinside.com 2019 - 2024. All rights reserved.