Algolia reindex command fails with exception in urllib3

拥有回忆 提交于 2020-01-04 21:38:12

问题


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

I get the following

    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...


回答1:


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)


来源:https://stackoverflow.com/questions/31768429/algolia-reindex-command-fails-with-exception-in-urllib3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!