influxdata / influxdb-client-python

InfluxDB 2.0 python client
https://influxdb-client.readthedocs.io/en/stable/
MIT License
723 stars 187 forks source link

InfluxDBClient: client.health() returns "...AttributeError: 'InfluxDBClient' object has no attribute 'health'..." #609

Closed integraciones-tiagora closed 6 months ago

integraciones-tiagora commented 1 year ago

Specifications

Dear sirs: I am running my Python script on PyCharm 2022.3.3 (Community Edition). My call to InfluxDB works OK, but I would like to add some checks to my program in case the connection fails.

I found that I should use the following sentences:

health = client.health() if health.status == "pass": print("Connection OK") else: print(f"Connection error: {health.message}!")

But my interpreter fails with the following error message:

health = client.health() AttributeError: 'InfluxDBClient' object has no attribute 'health'

¿ Do I need to upgrade my client? ¿Or is there any other available way to check the health of my connection?

Your help will be greatly appreciated Best regards Rogelio

Code sample to reproduce problem

client = InfluxDBClient(host='10.235.2.19', port=8086, username='admin', password='nimda') client.switch_database('telegraf')

health = client.health() if health.status == "pass": print("Conexión exitosa a InfluxDB.") else: print(f"Error de conexión a InfluxDB: {health.message}!")

Expected behavior

I expect client.health() to return a pass or the error code

Actual behavior

My program fails with the following error message:

health = client.health() AttributeError: 'InfluxDBClient' object has no attribute 'health'

Additional info

No response

bednar commented 1 year ago

Hi @integraciones-tiagora,

¿ Do I need to upgrade my client? ¿Or is there any other available way to check the health of my connection?

You have to use the v2 client: https://github.com/influxdata/influxdb-client-python#pip-install. You are currently using the v1 client.

Regards

integraciones-tiagora commented 1 year ago

Thanks! I will try it and let you know.

Best regards, Rogelio