ElasticSearchAPI

8i9zcol2  于 2022-11-22  发布在  ElasticSearch
关注(0)|答案(1)|浏览(124)

嘿,斯塔克溢出的家人,
我正在开发一个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 .即通过用户名和密码进行授权。有人能帮助我吗?

lvmkulzt

lvmkulzt1#

对于Basic Auth的请求,如果您通过 Postman 请求,则可以在Authentication选项卡中提供凭据。但是对于Code/Console/Browser,必须在请求URL中提供证书。
例如:

https://username:password@URL
https://admin:admin@www.the-internet.herokuapp.com/basic_auth

相关问题