diff --git a/src/connector/python/taos/cinterface.py b/src/connector/python/taos/cinterface.py index fadef7c39746dddb8fcf647f555d857c04b6efec..7977a6bc025f9cbb82fcda5d0900ae8110f2875d 100644 --- a/src/connector/python/taos/cinterface.py +++ b/src/connector/python/taos/cinterface.py @@ -838,8 +838,14 @@ def taos_insert_telnet_lines(connection, lines): p_lines = lines_type(*lines) errno = _libtaos.taos_insert_telnet_lines(connection, p_lines, num_of_lines) if errno != 0: - raise LinesError("insert telnet lines error", errno) + raise TelnetLinesError("insert telnet lines error", errno) +def taos_insert_json_payload(connection, payload): + # type: (c_void_p, list[str] | tuple(str)) -> None + payload = payload.encode("utf-8") + errno = _libtaos.taos_insert_json_payload(connection, payload) + if errno != 0: + raise JsonPayloadError("insert json payload error", errno) class CTaosInterface(object): def __init__(self, config=None): diff --git a/src/connector/python/taos/connection.py b/src/connector/python/taos/connection.py index a8a71ecc3a8a5f2bdc960df364213e80018a70fe..35aca1fb26c1e612c3b3f6b1d8c794495bed0035 100644 --- a/src/connector/python/taos/connection.py +++ b/src/connector/python/taos/connection.py @@ -154,6 +154,25 @@ class TaosConnection(object): """ return taos_insert_telnet_lines(self._conn, lines) + def insert_json_payload(self, payload): + """OpenTSDB HTTP JSON format support + + ## Example + "{ + "metric": "cpu_load_0", + "timestamp": 1626006833610123, + "value": 55.5, + "tags": + { + "host": "ubuntu", + "interface": "eth0", + "Id": "tb0" + } + }" + + """ + return taos_insert_json_payload(self._conn, payload) + def cursor(self): # type: () -> TaosCursor """Return a new Cursor object using the connection.""" diff --git a/src/connector/python/taos/error.py b/src/connector/python/taos/error.py index a30adbb162f1c194bdfcf4cca5c43f01107a9776..f6a9d41f56a3fb071080daaae3bdd840190b154d 100644 --- a/src/connector/python/taos/error.py +++ b/src/connector/python/taos/error.py @@ -83,4 +83,14 @@ class ResultError(DatabaseError): class LinesError(DatabaseError): """taos_insert_lines errors.""" - pass \ No newline at end of file + pass + +class TelnetLinesError(DatabaseError): + """taos_insert_telnet_lines errors.""" + + pass + +class JsonPayloadError(DatabaseError): + """taos_insert_json_payload errors.""" + + pass