I’m trying to receive inserted data points in a custom script. However, I just cannot find out how to get the actual data point from the HTTP request.
I’ve configured a subscription in my influx db and enabled subscriptions in the config. The subscription works if I start another influxdb in docker on the specified port, the data point is replicated. But in a simple python script using flask, the form parameters are shown as empty. Additionally, when I send an influx line via curl to the flask server, it is properly received.
Here is the output of “show subscriptions”:
show subscriptions name: datalogger retention_policy name mode destinations ---------------- ---- ---- ------------ autogen replication ALL [http://localhost:8087]
Output from influxdb.service:
Jun 03 21:23:15 philipp-desktop influxd[2683]: [httpd] 127.0.0.1 - - [03/Jun/2020:21:23:15 +0200] "POST /write?consistency=all&db=datalogger&precision=ns&rp= HTTP/1.1" 204 0 "-" "InfluxDBShell/1.7.10" ac25a3c0-a Jun 03 21:23:16 philipp-desktop influxd[2683]: [httpd] 127.0.0.1 - - [03/Jun/2020:21:23:16 +0200] "POST /write?consistency=all&db=datalogger&precision=ns&rp= HTTP/1.1" 204 0 "-" "InfluxDBShell/1.7.10" ac9c03dc-a Jun 03 21:23:16 philipp-desktop influxd[2683]: [httpd] 127.0.0.1 - - [03/Jun/2020:21:23:16 +0200] "POST /write?consistency=all&db=datalogger&precision=ns&rp= HTTP/1.1" 204 0 "-" "InfluxDBShell/1.7.10" acfeed2e-a
The flask script:
from flask import Flask, request app = Flask(__name__) @app.route('/write', methods=['POST']) def result(): print("Request form:", request.form) return ""
Its output:
127.0.0.1 - - [03/Jun/2020 21:23:15] "POST /write?consistency=&db=datalogger&precision=ns&rp=autogen HTTP/1.1" 200 - Request form: ImmutableMultiDict([]) 127.0.0.1 - - [03/Jun/2020 21:23:16] "POST /write?consistency=&db=datalogger&precision=ns&rp=autogen HTTP/1.1" 200 - Request form: ImmutableMultiDict([]) 127.0.0.1 - - [03/Jun/2020 21:23:16] "POST /write?consistency=&db=datalogger&precision=ns&rp=autogen HTTP/1.1" 200 - Request form: ImmutableMultiDict([])
Curl command:
curl -i -XPOST "http://localhost:5000/write?db=mydb&precision=s" --data-binary 'mymeas,mytag=1 myfield=90 1463683075'
Output of the flask script after the curl command:
Request form: ImmutableMultiDict([('mymeas,mytag', '1 myfield=90 1463683075')]) 127.0.0.1 - - [03/Jun/2020 21:27:25] "POST /write?db=mydb&precision=s HTTP/1.1" 200 -
This thread seems similar, but hasn’t gotten any answers: How Can I receive complete subscribed data via http server
What am I doing wrong?