本文介绍了Algolia reindex 命令在 urllib3 中失败并出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 django 项目中使用 algolia.但是,我遇到了这个我以前从未见过的奇怪异常.当我运行命令时,

I'm trying to use algolia with my django project. However, i've been running into this strange exception that I have not seen before. When I run the command,

python3 manage.py algolia_reindex

python3 manage.py algolia_reindex

我得到以下

    The following models were reindexed:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/util.py", line 144, in _validate_timeout
    float(value)
TypeError: float() argument must be a string or a number, not 'tuple'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.4/dist-packages/django/contrib/algoliasearch/management/commands/algolia_reindex.py", line 22, in handle
    batch_size=options.get('batchsize', None))
  File "/usr/local/lib/python3.4/dist-packages/django/contrib/algoliasearch/models.py", line 207, in reindex_all
    self.__tmp_index.clear_index()
  File "/usr/local/lib/python3.4/dist-packages/algoliasearch/index.py", line 560, in clear_index
    return self._perform_request(self.write_hosts, '/clear', 'POST')
  File "/usr/local/lib/python3.4/dist-packages/algoliasearch/index.py", line 792, in _perform_request
    params=params, body=body, is_search=is_search)
  File "/usr/local/lib/python3.4/dist-packages/algoliasearch/client.py", line 499, in _perform_request
    params=params, data=body, timeout=timeout)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 455, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 558, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 316, in send
    timeout = TimeoutSauce(connect=timeout, read=timeout)
  File "/usr/lib/python3/dist-packages/urllib3/util.py", line 116, in __init__
    self._connect = self._validate_timeout(connect, 'connect')
  File "/usr/lib/python3/dist-packages/urllib3/util.py", line 147, in _validate_timeout
    "int or float." % (name, value))
ValueError: Timeout value connect was (1, 30), but it must be an int or float.

谁能帮我解决这个问题.它似乎不是来自我的任何文件.所以,我认为这只是一个配置问题...

Can anyone help me resolve this problem. It doesn't seem to be from any of my files. So, I think this is just a config problem...

推荐答案

发生此错误的原因是您的 urllib3requests 版本之间不兼容.你可以通过更新urllib3requests来解决这个问题:

This error happens because of an incompatibility between your urllib3 and requests version. You can solve the problem by updating urllib3 and requests:

pip install --upgrade urllib3 requests

另一种解决方法是在应用程序的 应用配置.

Another workaround is to define a custom value for the timeout, in your application's AppConfig.

from django.apps import AppConfig
from django.contrib import algoliasearch

class YourAppConfig(AppConfig):
    name = 'your_app'

    def ready(self):
        algoliasearch.algolia_engine.client.timeout = 30
        algoliasearch.algolia_engine.client.search_timeout = 5

        YourModel = self.get_model('your_model')
        algoliasearch.register(YourModel)

这篇关于Algolia reindex 命令在 urllib3 中失败并出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 19:40