Json URI 中的对象

Json object in URI

我正在尝试在 python 中查询我的弹性搜索服务器,如果我在我的 python (search()) 脚本中硬编码 url 和查询字符串,如下所示没问题。如果我想存储那些 url 并在单独的 xml 文件(属性 文件)中查询。我没有得到结果,而是收到以下错误:

text    '{"error":{"root_cause":[{"type":"parsing_exception","reason":"Expected [START_OBJECT] but found [VALUE_STRING]","line":1,"col":1}],"type":"parsing_exception","reason":"Expected [START_OBJECT] but found [VALUE_STRING]","line":1,"col":1},"status":400}' str

这是我正在使用的代码

def search():          
        url="http://0.0.0.0/logstash-pse*/_search/"
        query={  "size": 0,  "aggs": {    "2": {      "date_histogram": {        "field": "@timestamp",        "interval": "30m",        "time_zone": "America/Chicago",        "min_doc_count": 1      },      "aggs": {        "3": {          "terms": {            "field": "queryname.keyword",            "size": 100,            "order": {              "1.90": "desc"            }          },          "aggs": {            "1": {              "percentiles": {                "field": "queryResponseTime",                "percents": [                  90                ],                "keyed": "false"              }            }          }        }      }    }  },  "query": {    "bool": {      "must": [        {          "query_string": {            "query": "path: \"/store_locator/\"",            "analyze_wildcard": "true"          }        },        {          "query_string": {            "analyze_wildcard": "true",            "query": "*"          }        },        {          "range": {            "@timestamp": {              "gte": 1527181463371,              "lte": 1527267863371,              "format": "epoch_millis"            }          }        }      ],      "must_not": []    }  },  "highlight": {    "pre_tags": [      "@kibana-highlighted-field@"    ],    "post_tags": [      "@/kibana-highlighted-field@"    ],    "fields": {      "*": {        "highlight_query": {          "bool": {            "must": [              {                "query_string": {                  "query": "path: \"/store_locator/\"",                  "analyze_wildcard": "true",                  "all_fields": "true"                }              },              {                "query_string": {                  "analyze_wildcard": "true",                  "query": "*",                  "all_fields": "true"                }              },              {                "range": {                  "@timestamp": {                    "gte": 1527181463371,                    "lte": 1527267863371,                    "format": "epoch_millis"                  }                }              }            ],            "must_not": []          }        }      }    },    "fragment_size": 2147483647  },  "_source": {    "excludes": []  },  "version": "true"}          

        response = requests.post(url, auth=(user, password), verify=False,json=query) 

XML 属性 我正在使用的文件如下所示:

<custom>
<url>the above url goes here</url>
<query> above query </query>
</custom>

知道我错过了什么吗?非常感谢

我自己通过一些练习就能搞定。如果有人正在寻找:

我刚用了下面的

response = requests.post(url, auth=(user, password), verify=False,json=json.loads(query))