Код: Выделить всё
python influx.py
Traceback (most recent call last): File "/home/fluffy/Code/python/influx.py", line 14, in
write_api = influxdb_client.write_api(write_options=SYNCHRONOUS)
^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'influxdb_client' has no attribute 'write_api'. Did you mean: 'WriteApi'?
Код: Выделить всё
import influxdb_client, os, time
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
token = os.environ.get("INFLUXDB_TOKEN")
print(token)
org = "fluffy"
url = "http://localhost:8086"
write_client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)
bucket="test"
write_api = influxdb_client.write_api(write_options=SYNCHRONOUS)
for value in range(5):
point = (
Point("measurement1")
.tag("tagname1", "tagvalue1")
.field("field1", value)
)
write_api.write(bucket=bucket, org="fluffy", record=point)
time.sleep(1) # separate points by 1 second
- ОС: Ubuntu 22.04.5 LTS
- Python: 3.12.7
- клиент influxdb: 1.47.0
Подробнее здесь: https://stackoverflow.com/questions/792 ... -write-api
Мобильная версия