influxdb-python icon indicating copy to clipboard operation
influxdb-python copied to clipboard

Write points returning no error but not writing into influxdb.

Open kunal-arora opened this issue 5 years ago • 10 comments

  • InfluxDB version: 1.7.8
  • InfluxDB-python version: 5.2.2
  • Python version: 3.6.8
  • Operating system version: Ubuntu 18.04 (EC2)
  • Nginx: nginx/1.16.1
  • Flask: 1.1.0

client.write_points(jsonData, time_precision='ms', protocol='json')

I am using this to write into influxdb, it was working fine then I dropped the database and created a new one, since then it has not been writing on influxdb only when the request is made from the flask api thats hosted on the same EC2. If requested from a different server eg: localhost, it works fine. I believe its some cache issue and it has frustrated me to the core. I have rebooted, stopped and re-launched, uninstalled influx and reinstalled still no effect.

When I hit there's this log: Oct 17 09:02:16 ip-172-31-11-234 influxd[2548]: [httpd] 127.0.0.1 - <username> [17/Oct/2019:09:02:16 +0000] "POST /write?db=buildings_data_staging_one&precision=ms HTTP/1.1" 204 0 "-" "python-requests/2.22.0" d12d0d15-f0bc-11e9-801a-02f6d7ec92de 89

Came here cos I couldn't think of anything.

kunal-arora avatar Oct 17 '19 09:10 kunal-arora

This is because of protocole. if you change it to 'line', it will work. but I see that it does not store the timestamp correctly.

salmanshahid8 avatar Oct 22 '19 12:10 salmanshahid8

But everything works normal when I use my local setup to access the ec2 influx instance. Dont get why it is not working for requests from that specific instance of python code.

kunal-arora avatar Oct 29 '19 02:10 kunal-arora

@kunal-arora can you try adding database=<your_database_name> within the client.write_points() API? e.g.

 client.write_points(jsonData, time_precision='ms', protocol='json', database='test')

shantanoo-desai avatar Oct 29 '19 08:10 shantanoo-desai

@shantanoo-desai it doesn't make any difference, as you can see in the log the database is being passed in correctly and if I put in a wrong database it throughs me an influxdb error. So I do not think its something related to the syntax. The same syntax works If I hit the same db from a different host.

kunal-arora avatar Nov 04 '19 00:11 kunal-arora

Any update on this ?

basiths avatar Jul 29 '20 11:07 basiths

I just run into the same problem, that the data were not visible in the influx database. Even tough, client.write_points() did return True.

I noticed, that the time was not correctly formatted in the json. So I had to correct the time format to datetime.datetime.utcnow().isoformat() which will be '2020-08-15T14:36:24.025388'

Below you will find the json_body, that is transmitted. json_body = [ { "measurement" : "weather_station", "location": "Home", "tags" : { "host" : "Innoxel", "Region" : "Home" }, "time" : datetime.datetime.utcnow().isoformat(), "fields": { 'temperatureAir': 23.8, 'humidity': 68.0, } } ]

jeromefischer avatar Aug 16 '20 09:08 jeromefischer

@jeromefischer: I run into the same problem, write_points() isn't inserting new measurements into Influxdb. I tried to update the time field as you said earlier but it didn't work.

How did you solve the issue ? Thanks

nhat-tong avatar Nov 10 '20 22:11 nhat-tong

I have a very similar problem: when I run my python code on google cloud, the write_api of influxdb_client does not do anything nor raise an error, but running the same code locally the write_api works perfectly. I use the following methods: client=influxdb_client.InfluxDBClient(url, token, debug=True, org=org) query_api = client.query_api() write_api = client.write_api() p = influxdb_client.Point("my_measurment").field(field, val).time(now+tz.utcoffset(datetime.now())) write_api.write(bucket=bucket, org=org, record=p)

lennartklfhs avatar Nov 03 '21 15:11 lennartklfhs

Hi @lennartklfhs,

your question is related to v2 client - influxdb-client-python.

The default configuration of write_api uses underlaying queue to insert batches into InfluxDB. You have to call write_api.close() to flush data or you can use client.write_api(write_options=SYNCHRONOUS) for direct writes into database.

  • https://influxdb-client.readthedocs.io/en/stable/usage.html#synchronous-client
  • https://influxdb-client.readthedocs.io/en/stable/usage.html#write
  • https://github.com/influxdata/influxdb-client-python/blob/master/examples/write_api_callbacks.py

Regards

bednar avatar Nov 04 '21 09:11 bednar

Did anyone found the root cause of this problem?

boshng95 avatar Jul 11 '22 13:07 boshng95