theCode
theCode

Reputation: 2347

Error 400 while inserting data to elasticseach with python requests

Hello I an trying to add data to my elasticsearch on my localhost. I found and example of post request:

data = {"key": "value", 'time_utc': time.strftime('%Y-%m-%dT%H:%M:%S')}
print data
r = requests.post('http://localhost:9200/macs/', json.dumps(data))
print r

But this give error(<Response [400]> ) and I am not understanding why. Can someone help ?

Upvotes: 1

Views: 1511

Answers (1)

lialzm
lialzm

Reputation: 36

requests.post('http://localhost:9200/macs/', data=json.dumps(data),headers={'Content-Type': 'application/json'})

Upvotes: 1

Related Questions