TDengine/docs/examples/python/query_ws.py

21 lines
555 B
Python
Raw Normal View History

2024-08-02 08:20:50 +00:00
import taosws
conn = None
2024-08-12 06:13:31 +00:00
host="localhost"
port=6041
2024-08-02 08:20:50 +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 08:20:50 +00:00
result = conn.query("SELECT ts, current, location FROM power.meters limit 100")
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 08:20:50 +00:00
except Exception as err:
2024-08-12 06:13:31 +00:00
print(f"Failed to query data from power.meters, db addr:{host}:{port} ; err:{err}")
2024-08-02 08:20:50 +00:00
finally:
if conn:
conn.close()