I’m encountering an issue with writing data to an InfluxDB instance running in a Docker container ( (influxdb:latest) on another machine within my local network. I’m using the InfluxDB Python client.
I can access the InfluxDB UI through a web browser at http://ip_other_machine:8086, so network connectivity seems fine.
Here’s the Python script I’m using to write data:
from datetime import datetime
from influxdb_client import InfluxDBClient, Point, WritePrecision
InfluxDB credentials and details
influxdb_host = ‘http://ip_other_machine:8086’
token = ‘TOKEN’
org = ‘My_ORG’
bucket = ‘MY_BUCKET’
Initialize InfluxDB client
with InfluxDBClient(url=influxdb_host, token=token, org=org) as client:
write_api = client.write_api()
# Create a Point structure
point = Point("test_measurement")
.tag("location", "test_location")
.field("value", 123.45)
.time(datetime.utcnow(), WritePrecision.NS)
# Write data to InfluxDB
try:
write_api.write(bucket=bucket, record=point)
print("Data sent to InfluxDB successfully.")
except Exception as e:
print(f"Error sending to InfluxDB: {e}")
The script executes without errors and indicates “Data sent to InfluxDB successfully.”
However, when I check the InfluxDB UI, no data appears.
I’ve confirmed that the token used has write permissions for the bucket ‘[MY_BUCKET]’.
I’m not sure what I’m doing wrong and would appreciate any insights or suggestions!
Thanks in advance!
2
Answers
Changed the scrip to:
No idea why the first script didn't work
Did you check the timerange of the UI?
I had similar problems, and the error was a result of a wrong timestamp given by Python. Maybe you try to not send the timestamp. Then the timestamp is automatically the actual time. Check if this data will appear.