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-12 11:33:50 +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()
|
|
|
|
|
|