【问题标题】:Django Haystack connection error using http authentication使用http身份验证的Django Haystack连接错误
【发布时间】:2015-02-24 23:29:41
【问题描述】:

我正在使用 Haystack 与安装的 elasticsearch 进行连接和交互。 Elasticsearch 安装在与主网络服务器不同的盒子上。

我已经使用 nginx 在 elasticsearch 框上设置了 HTTP 身份验证。这是为了阻止对 elasticsearch 的未经授权的访问。

Haystack 配置如下所示:

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://USERNAME:PASSWORD@DOMAIN:PORT/',
        'INDEX_NAME': 'haystack',
    },
}

通过这个设置我得到一个连接错误:

elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.',
gaierror(-2, 'Name or service not known'))) caused by: ProtocolError(('Connection
aborted.', gaierror(-2, 'Name or service not known')))

如果我关闭 HTTP 身份验证并将 URL 相应地更新为 http://DOMAIN:PORT/,它可以毫无问题地连接。

可能是 Haystack(或 elasticsearch-py (http://www.elasticsearch.org/guide/en/elasticsearch/client/python-api/current/) 不允许在 URL 中使用 HTTP 身份验证?我注意到这是 Solr 的问题 - Solr authentication (using Django Haystack)

【问题讨论】:

    标签: django elasticsearch django-haystack http-authentication pyelasticsearch


    【解决方案1】:

    对于其他有同样问题的人,将 kwargs 添加到配置中:

    'KWARGS': {
        'port': parsed.port,
        'http_auth': (parsed.username, parsed.password),
    }
    

    见:https://github.com/toastdriven/django-haystack/issues/1046

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2013-01-08
      • 2014-07-18
      • 1970-01-01
      • 1970-01-01
      • 2019-09-18
      • 2020-09-04
      相关资源
      最近更新 更多