from nebulagraph_python.client import NebulaClient
from nebulagraph_python.error import NebulaGraphRemoteError
from nebulagraph_python.client._session_pool import SessionPoolConfig
# size连接池大小 wait_timeout单位秒
pool_config = SessionPoolConfig(size=20, wait_timeout=10.0)
client = NebulaClient(
hosts=["127.0.0.1:9669"],
username="root",
password="Nebula123",
session_pool_config=pool_config
)
query = """
use #tmp_dev match (v@person where v.person_id = '1') return v next use #tmp_dev match p = simple (v)-[e:guarantee]-{1,9}(v) return p
"""
# Execute query
try:
result = client.execute(query, timeout=6000)
except NebulaGraphRemoteError as e:
# 捕获 Nebula 语法或执行错误
print(f"Nebula 查询失败: {e}")
print(f"错误码: {e.code}")
print(f"错误消息: {e.message}")
# 可选:记录日志、通知用户、回退逻辑等
except Exception as e:
# 捕获其他意外异常(如网络、连接问题)
print(f"未知错误: {e}")
#1. 逐行遍历记录(推荐用于处理大量数据)
for record in result.records():
print(record)