-
Notifications
You must be signed in to change notification settings - Fork 185
How to determine possible failures during write api #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @witanswer, thanks for using our client.
The
You can use something like: import json
import urllib3
from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS
from influxdb_client.rest import ApiException
url = "http://localhost:8086"
token = "my-token"
bucket = "my-bucket"
org = "my-org"
with InfluxDBClient(url=url, token=token, org=org) as client:
write_api = client.write_api(write_options=SYNCHRONOUS)
"""
Write data
"""
try:
write_api.write(bucket=bucket, record="mem,location=aws-va523 value=1")
except ApiException as e:
# missing credentials
if e.status == 401:
raise Exception(f"Incorrect authentication...") from e
# badly formatted
if e.status == 400:
message = json.loads(e.body)['message']
raise Exception(f"Badly formatted... '{message}'.") from e
raise
except urllib3.exceptions.TimeoutError as e:
raise Exception(f"Timeout...") from e Regards |
Sounds good, thanks for the assistance. |
But what if the write is not synchronous, for example when using batch write, how can I know if an error has occurred? |
Hi @ronytesler, thanks for using our client. The version For more info see docs:
Regards |
@bednar Thanks. So I can use: I thought that if the call is ASYNCHRONOUS, I can't just catch the error like this. |
The https://github.com/influxdata/influxdb-client-python#asynchronous-client |
Hello, I am working on a piece of code to send influxdb formatted files on the local filesystem to our influxdb server.
I would like to be able to assure that a file's data has been successfully sent to the server before removing the local file.
In example code, It seems that the return values of write are not checked (as far as i can tell):
https://github.com/influxdata/influxdb-client-python/blob/master/examples/import_data_set.py#L73
And from reading the api, It seems that if the request is synchronus, it returns None
https://github.com/influxdata/influxdb-client-python/blob/master/influxdb_client/client/write_api.py#L257
I would like to have the option to take action in certain conditions, IE:
-A badly formatted line among a large number of well formed lines
-Timeout longer than configured has occured
-Incorrect authentication has been given
How would I go about detecting this in code?
Thank you!
The text was updated successfully, but these errors were encountered: