gpt4 book ai didi

python - Elasticsearch HTTPConnectionPool(主机='127.0.0.1',端口=9200): Max retries exceeded

转载 作者:行者123 更新时间:2023-12-01 05:27:43 31 4
gpt4 key购买 nike

我有一个 Elastic Search 服务器,我可以从实时网站并通过 Django 管理命令对其进行查询。管理命令在格林威治标准时间凌晨 3 点使用 celerybeat 运行,以同步来自外部服务的数据。有时(但不是每次)运行此命令时,elastic search 似乎会崩溃,并且我在错误日志中收到以下错误。

    [09/Jan/2014 08:03:46] ERROR [django.request:212] Internal Server Error: /
Traceback (most recent call last):
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/django/core/handlers/base.py",
line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/django/views/generic/base.py",
line 68, in view
return self.dispatch(request, *args, **kwargs)
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/django/views/generic/base.py",
line 86, in dispatch
return handler(request, *args, **kwargs)
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/django/views/generic/base.py",
line 153, in get
context = self.get_context_data(**kwargs)
File
"/srv/www/site.co.uk/clothes_comparison/clothes_comparison/views.py",
line 56, in get_context_data
fields=['id', 'name', 'price', 'images', 'advertiser']
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/pyelasticsearch/client.py",
line 96, in decorate
return func(*args, query_params=query_params, **kwargs)
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/pyelasticsearch/client.py",
line 512, in multi_get
'GET', ['_mget'], {'docs': docs}, query_params=query_params)
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/pyelasticsearch/client.py",
line 238, in send_request
**({'data': request_body} if body else {}))
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/requests/sessions.py",
line 347, in get
return self.request('GET', url, **kwargs)
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/requests/sessions.py",
line 335, in request
resp = self.send(prep, **send_kwargs)
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/requests/sessions.py",
line 438, in send
r = adapter.send(request, **kwargs)
File
"/srv/www/site.co.uk/env/local/lib/python2.7/site-packages/requests/adapters.py",
line 327, in send
raise ConnectionError(e)
ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=9200): Max
retries exceeded with url: /_mget (Caused by <class 'socket.error'>: [Errno 111]
Connection refused)

我正在使用 pyelasticsearch 连接到 Elastic Search,在我的 settings.py 文件中包含以下代码:

try:
ES_CON
except NameError:
ES_CON = None

if not ES_CON:
ES_CON = ElasticSearch(ELASTICSEARCH_URI)

任何帮助将不胜感激。

最佳答案

我建议使用官方 Elasticsearch python 客户端:elasticsearch-py它具有可靠的连接处理、线程安全等。它也更快(根据 Elasticsearch 团队成员的作者的说法)。

然后,您可以将 es = Elasticsearch() 放在 tasks.py 的顶部,或者放在例如core.helpers 并从那里导入 es

关于python - Elasticsearch HTTPConnectionPool(主机='127.0.0.1',端口=9200): Max retries exceeded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21015135/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com