How to insert/store a string value in influxdb measurement?

How to insert/store a string value in influxdb measurement?

I am trying to insert some string value in influx db but keep getting 400 error. I am iusing python requests module to connect to influxdb. Here is my code:
description = ‘”‘ + some_str + ‘”‘
payload = “%s, name=%s, description=%s, count=%d %d” %(measurement, name, description,count,timestamp)
requests.post(influx_uri, data=payload, headers= headers)

I keep getting this error:
400 {“error”:”unable to parse ‘sample,name=sample, description=\”some_str\”, count=1 15106068120000000’ : missing tag key”}

I don’t know how this is getting generated description=\”some_str\”

Solutions/Answers:

Solution 1:

OK. Another attempt.

By reading the docs there’s no mention of putting quotes around long strings. Instead they say you should escape spaces with a backslash:

Escaping Characters

If a tag key, tag value, or field key contains a space , comma ,, or
an equals sign = it must be escaped using the backslash character .
Backslash characters do not need to be escaped. Commas , and spaces
will also need to be escaped for measurements, though equals signs =
do not.

Moreover you shouldn’t have spaces after commas. So I suggest you try:

Related:  Schema design in influxdb
description = "some\ str"
payload = "%s,name=%s,description=%s,count=%d %d" % (measurement, name, description,count,timestamp)

Solution 2:

I have never used influxdb, to be honest it’s the first time I hear of it, but…

By looking in the docs they seem to post a JSON content to the url using POST method, e.g.:

curl -X POST -d '[{"name":"foo","columns":["val"],"points":[[23]]}]' 'http://localhost:8086/db/mydb/series?u=root&p=root'

Your line doesn’t look like a JSON document. And you better make it. Not sure what is your structure, but maybe this could do the job?

payload = """{"name":"%s", "description":"%s", "count":"%d %d"}""" %(name, description, count, timestamp)

References