TDengine/docs/examples/python/query_rest.py

18 lines
537 B
Python
Raw Normal View History

2024-08-02 08:20:50 +00:00
import taosrest
client = None
2024-08-12 06:13:31 +00:00
url="http://localhost:6041"
2024-08-02 08:20:50 +00:00
try:
2024-08-12 06:13:31 +00:00
client = taosrest.RestClient(url=url,
2024-08-02 08:20:50 +00:00
user="root",
password="taosdata",
timeout=30)
2024-08-12 06:13:31 +00:00
result = client.sql(f"SELECT ts, current, location FROM power.meters limit 100")
if result["data"]:
for row in result["data"]:
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 11:33:50 +00:00
print(f"Failed to query data from power.meters, url:{url} ; ErrMessage:{err}")