gpt4 book ai didi

python - 使用python请求将数据插入elasticsearch时出现错误400

转载 作者:太空宇宙 更新时间:2023-11-03 16:23:25 25 4
gpt4 key购买 nike

您好,我正在尝试将数据添加到本地主机上的elasticsearch。我找到了发布请求的示例:

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

但这给出了错误( <Response [400]>)我不明白为什么。有人可以帮忙吗?

最佳答案

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

关于python - 使用python请求将数据插入elasticsearch时出现错误400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38213370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com