【问题标题】:creating a request to replace curl -XDelete - Python创建请求以替换 curl -XDelete - Python
【发布时间】:2016-10-14 06:20:22
【问题描述】:

我正在执行以下 cURL 命令来清理 Elastic Search 索引:

curl -s -XDELETE "http://<server>/<server_index>/<index>/_query" -d '{
    "query":{"match_all":{}}}
}'

但是,我不执行 shell 脚本或 subprocess 命令。相反,我想依靠requests 来实现这一点:

import requests
r = requests.get('http://<server>/<server_index>/<index>/_query')

我怎样才能做到这一点?

【问题讨论】:

    标签: python http post curl python-requests


    【解决方案1】:

    等效的请求代码应该是这样的:

    data = {"query": {"match_all": {}}}
    
    import requests
    
    r = requests.delete("http://<server>/<server_index>/<index>/_query", data=data)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2013-12-26
      • 2016-01-30
      • 2020-03-18
      • 2023-04-08
      相关资源
      最近更新 更多