0

I wanted to have the following script to document my speedtest data, however I get the following error message:

Traceback (most recent call last): File "/home/pi/speedtest.py", line 35, in client.write_points(speed_data,) AttributeError: 'InfluxDBClient' object has no attribute 'write_points'

What is the correct version of the script?

import re import subprocess from influxdb_client import InfluxDBClient
response = subprocess.Popen('/usr/bin/speedtest --accept-license --accept-gdpr', shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')

ping = re.search('Latency:\s+(.*?)\s', response, re.MULTILINE)
download = re.search('Download:\s+(.*?)\s', response, re.MULTILINE)
upload = re.search('Upload:\s+(.*?)\s', response, re.MULTILINE)
jitter = re.search('Latency:.*?jitter:\s+(.*?)ms', response, re.MULTILINE)

ping = ping.group(1)
download = download.group(1)
upload = upload.group(1)
jitter = jitter.group(1)

speed_data = [
    {
        "measurement" : "internet_speed",
        "tags" : {
            "host": "Speedlink"
        },
        "fields" : {
            "download": float(download),
            "upload": float(upload),
            "ping": float(ping),
            "jitter": float(jitter)
        }
    }
]
bucket = "SpeedtestMonitor"

client = InfluxDBClient(url="http://localhost:8086", token="oM8PyToLgv-404hbNvH6BEIldKbSHy6h8WGYQYwSwkz1qrPnJ7brf5aW5sdsdsWtQO7GVou4XQRt51N1p-ozMWw==", org="Schmidt")

client.write_points(speed_data,)

1
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a minimal reproducible example. Commented Feb 23, 2023 at 23:21

1 Answer 1

0

You are using the InfluxDB2 Python library (influxdb_client.) The InfluxDBClient class does not have a write_points method. Instead you will need to get an instance of write_api and use its write method to perform your write.

So instead of client.write_points(speed_data,) try the following:

write_api = client.write_api(write_options=SYNCHRONOUS)
write_api.write(bucket=bucket, record=speed_data)

See example from InfluxDB docs and write API documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.