,当我尝试使用python请求查询ElasticSearch时,我无法检索结果。这是我的代码:json_data = updateJson(sys.argv[1])
headers={'Accept': 'application/json', 'Content-type': 'application/json'}
elastic_url ='https://localhost:9200/logstash-kafka-wga-blueid-\*/_search'
query = json.dumps(json_data)
response = requests.get(elastic_url, data = query, auth=('xxx','xxx'), verify=False, headers = headers)
print response.text
我总是得到以下输出:
^{pr2}$
但是如果我尝试使用下面的CURL命令,就会得到正确的结果。在上面的代码json_数据中,从abc.json文件文件。上面的代码有错误吗?在curl -X GET -k -u xxx:xxx https://localhost:9200/logstash-kafka-wga-blueid-\*/_search -d @temporaryRundeckReport.json
下面是我的updateJson()方法:def updateJson(fileName):
with open(fileName, 'r') as file:
json_data = file.read()
json_data = json_data.replace('%X-FORWARDED-HOST%', sys.argv[2]);
json_data = json_data.replace('%TIME%', sys.argv[3]);
json_data = json_data.replace('%INTERVAL%', sys.argv[4]);
with open('temporaryRundeckReport.json', 'w+') as file:
os.chmod('temporaryRundeckReport.json',0o777)
file.write(json_data)
return json_data