Get batch write errors from python's influxdb_client package

I have this code:

  client = InfluxDBClient(
        url=influxdb_config['DATABASE_PROPERTIES']['HOST'] +
            ':' + influxdb_config['DATABASE_PROPERTIES']['PORT'],
        token=influxdb_config['DATABASE_PROPERTIES']['TOKEN'], retries=retries, enable_gzip=True)

    write_api = client.write_api(write_options=WriteOptions(
        flush_interval=300, max_retry_time=100))

write_api.write(bucket, org, data, write_precision=WritePrecision.US)

This uses batch writing. How can I know if errors have occurred?

Welcome to the community.
Please provide more information.
What is the error message exactly?
Which InfluxDB database version (1.x.x or 2.x.x) are you writing to?
Please show us some more coherent real code. The code shown can’t work at all as client is declared later?

Sorry, I edited the code. This is the real code and it works. I can try to write bad data and then I can put a breakpoint inside the package in this function:

    def _on_next(response: _BatchResponse):
        if response.exception:
            logger.error("The batch item wasn't processed successfully because: %s", response.exception)
            logger.debug("The batch item: %s was processed successfully.", response)

And here I can see that the error is:
Reason: Bad Request

But how can I be aware of that error in my code?

Hi @Franky1,

thanks for using our client.

The version 1.22.0 introduces possibility to handle batch events - feat(write): add support for callback notification for batching mode by bednar · Pull Request #341 · influxdata/influxdb-client-python · GitHub.

For more info see docs:


1 Like