skip to Main Content

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


  1. Chosen as BEST ANSWER

    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


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search