0

Does StackOverflow really autodeletes Hey guys from beginning of text? :D Hello, i have a problem i cant seem to wrap my mind around.

from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS

# You can generate a Token from the "Tokens Tab" in the UI
org = "myorg"
bucket = "mybucket"
token = 'valid_token'

client = InfluxDBClient(url="http://localhost:8086", token=token)

write_api = client.write_api(write_options=SYNCHRONOUS)

d='airSensors,sensor_id=TLM0201 temperature=70.97038159354763,humidity=55.23103248356096,co=0.78445310567793615 1637124357000000000'
write_api.write(bucket, org, d)

This runs and returns no error, i tried making a mistake in eg. bucket and it raises, bad token raises unauthorized, etc..

BUT there is no data in database when i check. BUT when i run this exact line through curl:

curl --request POST \
"http://localhost:8086/api/v2/write?org=myorg&bucket=mybucket&precision=ns" \
  --header "Authorization: Token valid_token" \
  --header "Content-Type: text/plain; charset=utf-8" \
  --header "Accept: application/json" \
  --data-binary '
    airSensors,sensor_id=TLM0201 temperature=73.97038159354763,humidity=35.23103248356096,co=0.48445310567793615 1637024357000000000
    airSensors,sensor_id=TLM0202 temperature=75.30007505999716,humidity=35.651929918691714,co=0.5141876544505826 1637024357000000000
    '

This runs also with no errors but this time it actually writes into db.

Am i crazy or what? I tried everything, writing through Points, series,... u name it but it refuses to commit or smthn? Anyone had similar problem?

I run influxdb-client=1.23.0 on python=3.8.10 and Influxdb=2.0.7

Thanks for ur time. Q.

Jan Janáček
  • 109
  • 1
  • 9

1 Answers1

0

I guess you should use write_api.close() in the end of your write or use with:

with client.write_api() as write_api:
    write_api.write(bucket, org, d)

https://github.com/influxdata/influxdb-client-python#writes

Aapo Rista
  • 121
  • 1
  • 4