TDengine/docs/examples/python/connect_example.py

26 lines
567 B
Python
Raw Normal View History

import taos
2024-08-01 13:07:55 +00:00
def create_connection():
# all parameters are optional.
2024-08-01 13:07:55 +00:00
conn = None
2024-08-03 13:58:17 +00:00
host = "localhost"
2024-09-24 11:24:20 +00:00
port = 6031
2024-08-01 13:07:55 +00:00
try:
2024-08-02 07:14:08 +00:00
conn = taos.connect(
2024-08-01 13:07:55 +00:00
user="root",
password="taosdata",
2024-08-03 13:58:17 +00:00
host=host,
port=port,
2024-08-01 13:07:55 +00:00
)
2024-08-03 13:58:17 +00:00
print(f"Connected to {host}:{port} successfully.");
2024-08-01 13:07:55 +00:00
except Exception as err:
2024-08-14 08:25:22 +00:00
print(f"Failed to connect to {host}:{port} , ErrMessage:{err}")
2024-09-24 11:24:20 +00:00
raise err
2024-08-01 13:07:55 +00:00
finally:
if conn:
conn.close()
if __name__ == "__main__":
2024-08-14 08:25:22 +00:00
create_connection()