嘿,斯塔克溢出的家人,
我正在开发一个API,它从ElasticSearch工具中提取请求并显示它。我正在尝试使用get request提取数据
import requests
import json
payload = {
"query": {
"match": {
"metric": "metric_name"
}
}
}
url = "https://url_name:9200/siren-kinesis*/_search"
payload = json.dumps(payload)
print(type(payload))
headers = {
'Content-Type': 'application/json',
}
result = requests.get(url=url,data=payload,headers=headers,auth=("test@example.com","*"))
print(result.json())
并得到以下错误
{
"error": {
"root_cause": [
{
"type": "security_exception",
"reason": "unable to authenticate user [test@example.com] for REST request [/_search]",
"header": {
"WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
}
}
],
"type": "security_exception",
"reason": "unable to authenticate user [test@example.com] for REST request [/_search]",
"header": {
"WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
}
},
"status": 401
}
我是Basic Auth .即通过用户名和密码进行授权。有人能帮助我吗?
1条答案
按热度按时间lvmkulzt1#
对于
Basic Auth
的请求,如果您通过 Postman 请求,则可以在Authentication
选项卡中提供凭据。但是对于Code/Console/Browser
,必须在请求URL中提供证书。例如: