[Python] GridDB_Python - Error: GSException during Put_Container

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    I'm encountering an error when trying to insert and select data using the GridDB Python client. Here's the code snippet:

    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()



    Error Message:

    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



    I got an empty message when printing the exception using this code snippet:

    try:
    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)
    except griddb.GSException as e:
    print(e)



    Steps Taken:

    1. Installed griddb-python following the official guide: https://pypi.org/project/griddb-python/
    2. Verified connection details (host, port, cluster name, username, password) using gs_sh and SQL Workbench. Both tools successfully connect and perform SQL operations on the container "iot_sensor".

    gs_sh output:

    gs[public]> showtable
    Database : public
    Name Type PartitionId
    ---------------------------------------------
    iot_sensor COLLECTION 30

    Total Count: 1

    gs[public]> select * from iot_sensor;
    2 results. (2 ms)
    gs[public]>



    SQL Workbench output:

    SQL> WbConnect -driver=com.toshiba.mwcloud.gs.sql.Driver -driverJar=/usr/share/java/gridstore-jdbc.jar -url=jdbc:gs://127.0.0.1:20001/myCluster/public -username=admin -password=admin;

    Connection to "User=admin, URL=jdbc:gs://127.0.0.1:20001/myCluster/public" successful

    SQL> select * from iot_sensor;

    iot_timestamp | iot_id | iot_value
    --------------------+-----------+----------
    2024-09-07 23:57:46 | sensor001 | 234.32
    2024-09-07 23:58:23 | sensor002 | 83.98

    (2 Rows)
    SELECT executed successfully



    Environment:

    WSL using GridDB version 5.5

    I am not sure, what I am missing here.

    Continue reading...

Compartilhe esta Página