Status code 400 on post message to influxdb
<p>I'm trying to post a json file to influxdb on my local host. This is the code:</p>

<pre><code>import json
import requests
url = 'http://localhost:8086/write?db=mydb'
files ={'file' : open('sample.json', 'rb')}
r = requests.post(url, files=files)
print(r.text)
</code></pre>

<p>This is what <code>sample.json</code> looks like:</p>

<pre><code>    {
            "region" : "eu-west-1",
            "instanceType": "m1.small"
    }
</code></pre>

<p>My response gives the following errors:</p>

<pre><code> {"error":"unable to parse '--1bee44675e8c42d8985e750b2483e0a8\r': 
 missing fields\nunable to parse 'Content-Disposition: form-data;
 name=\"file\"; filename=\"sample.json\"\r': invalid field 
 format\nunable   to parse '\r': missing fields\nunable to parse '{': 
 missing fields\nunable to parse '\"region\" : \"eu-west-1\",':  invalid 
 field format\nunable to parse '\"instanceType\": \"m1.small\"':  invalid 
 field format\nunable to parse '}': missing fields"}
</code></pre>

<p>My json seems to be a valid json file. I am not sure what I am doing wrong. </p>

<p>I think that the fault maybe is that you just open the file but not read it. I mean since you want to post the content of the <code>json</code> object which is stored on the file, and not the file itself, it may be better to do that instead:</p>

<pre><code>import json
import requests
url = 'http://localhost:8086/write?db=mydb'
json_data = open('sample.json', 'rb').read()   # read the json data from the file
r = requests.post(url, data=json_data) # post them as data
print(r.text)
</code></pre>

<p>which is actually your code modified just a bit...</p>

python json post influxdb http-status-code-400