python - Algolia reindex 命令在 urllib3 中失败并出现异常

标签 python django python-3.x search algolia

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

python3 管理.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.

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

最佳答案

出现此错误的原因是您的 urllib3requests 版本不兼容。您可以通过更新urllib3requests来解决问题:

pip install --upgrade urllib3 requests

另一个解决方法是在应用程序的 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)

关于python - Algolia reindex 命令在 urllib3 中失败并出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31768429/

相关文章:

python-3.x - 将 emacs python 模式解释器更改为 python3.5

python - 如何修复 Tensorflow 中的 "ValueError: Operands could not be broadcast together with shapes (2592,) (4,)"?

python - 如何在 Python 中使用 -p 选项运行 os.mkdir()?

python - 在 django-taggit 中,如何获取与特定用户关联的对象的标签?

django - Django 应用程序中的 "' 标记 ' is not a registered tag library. Must be one of"

python - "django.db.utils.ProgrammingError: relation "app_user "does not exist"在 manage.py 测试期间

python - 如何替换Excel中的字符串并检查整个单元格字符串?

python - zinnia django 中的 django.contrib.comments.moderation.AlreadyModerated 错误

python - 使用 Python 3 进行 URL 解码

python - 使用 timedelta 时小数位太多