pythondockerinfluxdb

InfluxDB: No Data in UI After Python Script Write


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!


Solution

  • Changed the scrip to:

    import influxdb_client
    from influxdb_client.client.write_api import SYNCHRONOUS
    
    # Your specific details
    influxdb_host = 'http://10.1.100.126:8086'
    token = 'MY_TOKEN'
    org = 'MY_ORG'
    bucket = 'MY_BUCKET'
    
    # Initialize the InfluxDB client
    client = influxdb_client.InfluxDBClient(
        url=influxdb_host,
        token=token,
        org=org
    )
    
    # Create the write API
    write_api = client.write_api(write_options=SYNCHRONOUS)
    
    # Create a line in InfluxDB Line Protocol
    line = "my_measurement,location=Prague temperature=25.3"
    
    # Write data
    write_api.write(bucket=bucket, org=org, record=line)
    

    No idea why the first script didn't work