importjsonimporttaosfromtaosimportSmlProtocol,SmlPrecisionlines=[{"metric":"meters.current","timestamp":1648432611249,"value":10.3,"tags":{"location":"Beijing.Chaoyang","groupid":2}},{"metric":"meters.voltage","timestamp":1648432611249,"value":219,"tags":{"location":"Beijing.Haidian","groupid":1}},{"metric":"meters.current","timestamp":1648432611250,"value":12.6,"tags":{"location":"Beijing.Chaoyang","groupid":2}},{"metric":"meters.voltage","timestamp":1648432611250,"value":221,"tags":{"location":"Beijing.Haidian","groupid":1}}]defget_connection():returntaos.connect()defcreate_database(conn):conn.execute("CREATE DATABASE test")conn.execute("USE test")definsert_lines(conn):globallineslines=json.dumps(lines)# note: the first parameter must be a list with only one element.affected_rows=conn.schemaless_insert([lines],SmlProtocol.JSON_PROTOCOL,SmlPrecision.NOT_CONFIGURED)print(affected_rows)# 4if__name__=='__main__':connection=get_connection()try:create_database(connection)insert_lines(connection)finally:connection.close()