AWS弹性搜索错误"[Errno 8] nodename或servname提供或未知."

neh*_*eha 10 python aws-elasticsearch

我创建了一个AWS elasticsearch实例.我想使用python脚本访问它.我指定了我的AWS配置(访问密钥,密钥,区域).我使用下面的代码来访问AWS ES实例:

from elasticsearch import Elasticsearch, RequestsHttpConnection
from requests_aws4auth import AWS4Auth

AWS_ACCESS_KEY = '**************'
AWS_SECRET_KEY = '*****************'
region = 'us-east-1'
service = 'es'

awsauth = AWS4Auth(AWS_ACCESS_KEY, AWS_SECRET_KEY, region, service)

host = 'https://kbckjsdkcdn.us-east-1.es.amazonaws.com' # For example, my-test-domain.us-east-1.es.amazonaws.com

es = Elasticsearch(
    hosts = [{'host': host, 'port': 443}],
    http_auth = awsauth,
    use_ssl = True,
    verify_certs = True,
    connection_class = RequestsHttpConnection
)

print es.info()
Run Code Online (Sandbox Code Playgroud)

当我运行上面的代码时,我收到以下错误:

elasticsearch.exceptions.ConnectionError:  ConnectionError(HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //search-opendata-2xd6pwilq5sv4ahomcuaiyxmqe.us-east-1.es.amazonaws.com:443/ (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10ee72310>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))) caused by: ConnectionError(HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //search-opendata-2xd6pwilq5sv4ahomcuaiyxmqe.us-east-1.es.amazonaws.com:443/ (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10ee72310>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)))
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个错误?

谢谢

Har*_*ari 19

Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known似乎表明elasticsearch客户端无法解析主机名.这可能是因为您包含https://主机中指定的协议.

将该行更改host = 'kbckjsdkcdn.us-east-1.es.amazonaws.com'为是否有效.您在那里的示例注释似乎表明该协议不应包含在主机变量中.

  • 很好的答案。网络上的大多数示例都是不正确的。而且就是这么简单... (2认同)