2

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

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.

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

4

1 回答 1

4

发生此错误是因为您的urllib3请求版本之间不兼容。您可以通过更新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)
于 2015-08-04T15:02:41.050 回答