elasticsearch,Python,elasticsearch" /> elasticsearch,Python,elasticsearch" />

如何使用API密钥和python库正确连接到Elasticsearch云?

如何使用API密钥和python库正确连接到Elasticsearch云?,python,elasticsearch,Python,elasticsearch,在下创建API密钥(托管在aws上) 文档应附加适当的身份验证标题: Authorization: ApiKey $EC_API_KEY 使用curl它可以工作: curl -i -H "authorization: ApiKey LONG_KEY_STRING==" https://12345.us-east-2.aws.elastic-cloud.com:9243/_health HTTP/2 200 x-cloud-request-id: 1234abc con

在下创建API密钥(托管在aws上)

文档应附加适当的身份验证标题:

Authorization: ApiKey $EC_API_KEY
使用
curl
它可以工作:

curl -i -H "authorization: ApiKey LONG_KEY_STRING=="  https://12345.us-east-2.aws.elastic-cloud.com:9243/_health

HTTP/2 200 
x-cloud-request-id: 1234abc
content-type: text/plain; charset=utf-8
content-length: 34
date: Thu, 22 Oct 2020 12:36:54 GMT

{
  "ok": true,
  "status": 200
}

但是以下python代码(
elasticsearch-7.9.1
)失败:

es=Elasticsearch(['https://12345.us-east-2.aws.elastic-cloud.com:9243“],api_key=“LONG_key_STRING==”)
打印(es.cluster.health())
有误:

{
    "errorMessage": "AuthenticationException(401, 'security_exception', 'missing authentication credentials for REST request [/_cluster/health]')",
    "stackTrace": [
        "  File \"/path/venv/lib64/python3.7/site-packages/lambda_local/main.py\", line 153, in execute\n    result = func(event, context._activate())\n",
        "  File \"main.py\", line 35, in handler\n    post_ping_doc(ping, msg[KEY_ID])\n",
        "  File \"main.py\", line 45, in post_ping_doc\n    print(es.cluster.health())\n",
        "  File \"/path/elasticsearch/client/utils.py\", line 152, in _wrapped\n    return func(*args, params=params, headers=headers, **kwargs)\n",
        "  File \"/path/elasticsearch/client/cluster.py\", line 69, in health\n    headers=headers,\n",
        "  File \"/path/elasticsearch/transport.py\", line 392, in perform_request\n    raise e\n",
        "  File \"/path/elasticsearch/transport.py\", line 365, in perform_request\n    timeout=timeout,\n",
        "  File \"/path/elasticsearch/connection/http_urllib3.py\", line 269, in perform_request\n    self._raise_error(response.status, raw_data)\n",
        "  File \"/path/elasticsearch/connection/base.py\", line 301, in _raise_error\n    status_code, error_message, additional_info\n"
    ],
    "errorType": "AuthenticationException"
}
在浏览网络时尝试了其他变体,结果都是一样的

启动本地
ncat-l 1234
,并将请求重定向到它。请求似乎合法

GET / HTTP/1.1
Host: 127.0.0.1:1234
Accept-Encoding: identity
connection: keep-alive
content-type: application/json
user-agent: elasticsearch-py/7.9.1 (Python 3.7.5)
authorization: ApiKey LONG_KEY_STRING==
Python代码可以在docker上使用本地不安全的ES(不需要任何密钥)

目前不在考虑范围内,欢迎提供任何帮助