TDengine/docs/examples/python/reqid_ws.py

26 lines
591 B
Python
Raw Permalink Normal View History

2024-08-02 18:51:12 +00:00
import taosws
conn = None
2024-08-12 12:56:20 +00:00
reqId = 3
2024-08-12 06:13:31 +00:00
host="localhost"
port=6041
2024-08-02 18:51:12 +00:00
try:
conn = taosws.connect(
user="root",
password="taosdata",
2024-08-12 06:13:31 +00:00
host=host,
port=port,
2024-08-02 18:51:12 +00:00
)
2024-08-12 12:56:20 +00:00
result = conn.query_with_req_id("SELECT ts, current, location FROM power.meters limit 100", req_id=3)
2024-08-12 06:13:31 +00:00
# Get data from result as list of tuple
2024-08-02 18:51:12 +00:00
for row in result:
2024-08-12 06:13:31 +00:00
print(f"ts: {row[0]}, current: {row[1]}, location: {row[2]}")
2024-08-02 18:51:12 +00:00
except Exception as err:
2024-08-14 08:25:22 +00:00
print(f"Failed to execute sql with reqId:{reqId}, ErrMessage:{err}")
2024-09-26 03:13:32 +00:00
raise err
2024-08-02 18:51:12 +00:00
finally:
if conn:
2024-08-12 12:56:20 +00:00
conn.close()