Skip to content
Advertisement

How to capture error messages via Python when inserting data in QuestDB?

Currently I am saving data to QuestDB through Python via the Influx Line Protocol (ILP) like so:

    import socket

    ilp_msg = 'my_table,name=server_timestamp value=12.4n'
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        sock.connect((HOST, PORT))
        sock.send((ilp_msg).encode())
    except socket.error as e:
        raise ValueError(f'Got error: {e}')
    sock.close()

If there is something wrong with my ilp_msg or the server or the DB, the above code will execute without raising any error. It will log into sdr out (or std err) on the DB.

My question: how can I save data to QuestDB via python and capture any error messages, so that I know that my save method has failed for a particular row.

Advertisement

Answer

The only way I see would be not using ILP but inserting rows by Postgres Driver psycopg2.

ILP seems like one way protocol to stream data to server in the manner of fire and forget.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement