You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GridDB Python客户端调用put_container触发GSException错误求助

GridDB Python客户端插入查询问题排查

问题描述

调用put_container方法时触发griddb_python.GSException,但捕获异常后无具体报错信息。

代码片段

import griddb_python as griddb
import datetime

factory = griddb.StoreFactory.get_instance()
gridstore = factory.get_store(
    host='127.0.0.1', 
    port=20001, 
    cluster_name='myCluster',
    username='admin', 
    password='admin'
)

conInfo = griddb.ContainerInfo(
    name="iot_sensor",
    column_info_list=[
        ["iot_timestamp", griddb.Type.TIMESTAMP],
        ["iot_id", griddb.Type.STRING],
        ["iot_value", griddb.Type.DOUBLE]
    ],
    type=griddb.ContainerType.TIME_SERIES,
    row_key=True)

ts = gridstore.put_container(conInfo)
ts.put([datetime.datetime.now(), "sensor003", 432.51])
ts.put([datetime.datetime.now(), "sensor004", 528.27])

rs = ts.query("SELECT * FROM iot_sensor")
rs = query.fetch()

while rs.has_next():
    data = rs.next()
    print(data)
    
gridstore.close()

报错信息

Traceback (most recent call last):
  File "/mnt/c/MyData/GridDB/pycode/insert.py", line 23, in <module>
    ts = gridstore.put_container(conInfo)
  File "/home/deekey/.local/lib/python3.10/site-packages/griddb_python.py", line 747, in put_container
    return _griddb_python.Store_put_container(self, info, modifiable)
griddb_python.GSException

已执行排查步骤

  • 按照官方指南完成griddb-python安装
  • 通过gs_sh和SQL Workbench验证连接信息(主机、端口、集群名、账号密码)正确,且容器"iot_sensor"可正常执行SQL操作

环境信息

  • WSL系统
  • GridDB版本5.5

解决建议

  1. 捕获异常并打印详细信息
    修改代码,在put_container调用处添加异常捕获,利用GSException的内置方法获取具体错误:

    try:
        ts = gridstore.put_container(conInfo)
    except griddb_python.GSException as e:
        print(f"错误代码: {e.get_error_code()}")
        print(f"错误详情: {e.get_message()}")
        raise
    

    这能直接输出容器已存在、权限不足、Schema不匹配等具体原因,是排查核心。

  2. 检查现有容器类型匹配性
    确认已存在的iot_sensor容器类型是否为TIME_SERIES,若之前创建的是普通集合,用put_container传入时间序列类型会报错:

    try:
        existing_container = gridstore.get_container("iot_sensor")
        print(f"现有容器类型: {existing_container.get_container_type()}")
    except griddb_python.GSException as e:
        print(f"获取容器失败: {e.get_message()}")
    
  3. 修正查询代码变量错误
    原代码查询部分存在变量名错误,rs = query.fetch()应改为rs = rs.fetch(),否则后续执行会触发未定义变量异常。

  4. 验证WSL网络连通性
    虽然连接信息正确,但WSL与宿主机的端口映射可能存在问题,用telnet 127.0.0.1 20001测试端口是否可访问,或尝试使用WSL内网IP作为host参数。


内容的提问来源于stack exchange,提问作者dede kyuti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 15:31:04