TDengine/docs/examples/python/connect_rest_example.py

24 lines
585 B
Python
Raw Permalink Normal View History

2024-08-02 08:20:50 +00:00
# ANCHOR: connect
import taosrest
def create_connection():
conn = None
2024-08-03 13:58:17 +00:00
url="http://localhost:6041"
2024-08-02 08:20:50 +00:00
try:
2024-08-03 13:58:17 +00:00
conn = taosrest.connect(url=url,
2024-08-02 08:20:50 +00:00
user="root",
password="taosdata",
timeout=30)
2024-08-03 10:04:12 +00:00
2024-08-03 13:58:17 +00:00
print(f"Connected to {url} successfully.");
2024-08-02 08:20:50 +00:00
except Exception as err:
2024-08-14 08:25:22 +00:00
print(f"Failed to connect to {url} , ErrMessage:{err}")
2024-08-02 08:20:50 +00:00
finally:
if conn:
conn.close()
# ANCHOR_END: connect
if __name__ == "__main__":
create_connection()