Martin S
Martin S

Reputation: 397

InfluxDB 2 introductory sample does not insert any data into the bucket, no error , no exception

I am new to influxdb and have also the issue that I can't insert data as it is reported in this post InfluxDB 2 introductory sample does not insert any data into the bucket

I am using the python example which is exactly the same as the C# example there. When I print the result of the write command then it is always 'None'.

from datetime import datetime
import influxdb_client

from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

# You can generate a Token from the "Tokens Tab" in the UI
token = "P-cve6BwhDLNu3o1MatDjZGIAex5Kn6TPEBlX1YxXJu4kUVSYKQH1i8DQThw7NhB1BO6uSaFyI-rUbVfSdFsIQ=="
org = "myOrg"
bucket = "mybucket1"
url="http://localhost:8086"

client = InfluxDBClient(url=url, token=token)
write_api = client.write_api(write_options=SYNCHRONOUS)

point = Point("my_measurement").tag("location",Prague").field("temperature", 25.3)

results = write_api.write(bucket, org, point)
print(results)

None

What am I doing wrong? I create a new token with all access, which was the solution in the other post, but that didn't help.

I am running both InfluxDB in Docker and jupyter notebook on Ubuntu in WSL2 on the same WIn10 machine.

Thanks in advance.

Update:

I meanwhile found that there is no issue in writing data into the db. The real issue is that the query is not working. The following code does the job.

query = 'from(bucket:"mybucket1")\
|> range(start: -12h)\
|> filter(fn:(r) => r._measurement == "my_measurement")\
|> filter(fn: (r) => r.location == "Prague")\
|> filter(fn:(r) => r._field == "temperature" )'
result = client.query_api().query(query, org=org)
results = []
for table in result:
  for record in table.records:
    results.append((record.get_field(), record.get_value()))

print(results)

Upvotes: 0

Views: 801

Answers (1)

Corralien
Corralien

Reputation: 120409

I already had a similar problem. I solved it with the code below:

# XXX: flush data
write_api.__del__()
client.__del__()

Upvotes: 2

Related Questions