使用http身份验证的Django Haystack连接错误

问题描述 投票:0回答:1

我正在使用 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?我注意到这是 Solr 的问题 - Solr 身份验证(使用 Django Haystack)

django elasticsearch django-haystack http-authentication pyelasticsearch
1个回答
5
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.