algolia reindex命令在urllib3中失败 [英] Algolia reindex command fails with exception in urllib3

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

问题描述

我试图用我的django项目使用algolia。但是,我一直在遇到这个奇怪的例外,我以前没见过。当我运行命令时,



python3 manage.py algolia_reindex



我得到以下

 以下模型被重新索引:
追溯(最近的最后一次调用):
文件/ usr / lib / python3 / dist-packages / urllib3 / util.py,第144行,_validate_timeout
float(value)
TypeError:float()参数必须是字符串或数字,而不是tuple

在处理上述异常时,发生另一个异常:

追溯(最近的最后一次调用):
文件manage.py,第10行在< module>
execute_from_command_line(sys.argv)
文件/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py,第338行,execute_from_command_line
utility.execute()
文件/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py,第330行,执行
self.fetch_command (子命令).run_from_argv(self.argv)
文件/usr/local/lib/python3.4/dist-packages/django/core/management/base.py,第393行,在run_from_argv
self.execute(* args,** cmd_options)
文件/usr/local/lib/python3.4/dist-packages/django/core/management/base.py,第444行,执行
output = self.handle(* args,** options)
文件/usr/local/lib/python3.4/dist-packages/django/contrib/algoliasearch/management/commands/algolia_reindex.py ,第22行,在句柄
batch_size = options.get('batchsize',无))
文件/usr/local/lib/python3.4/dist-packages/django/contrib/algoliasearch /models.py,第207行,在reindex_all中
self .__ tmp_index.clear_index()
文件/usr/local/lib/python3.4/dist-packages/algoliasearch/index.py,第560行,clear_index
返回自身._perform_request(self.write_hosts,'/ clear','POST')
文件/usr/local/lib/python3.4/dist-packages/algoliasearch/index.py,第792行,_perform_request
params = params,body = body,is_search = is_search)
文件/usr/local/lib/python3.4/dist-packages/algoliasearch/client.py,第499行,_perform_request
params = params,data = body,timeout = timeout)
文件/usr/lib/python3/dist-packages/requests/sessions.py,第455行,请求
resp = self .send(prep,** send_kwargs)
文件/usr/lib/python3/dist-packages/requests/sessions.py,第558行,发送
r = adapter.send(request,* * kwargs)
文件/usr/lib/python3/dist-packages/requests/adapters.py,第316行,发送
timeout = TimeoutSauce(connect = timeout,read = timeout)
文件/ usr / lib / python3 / dist-packa ges / urllib3 / util.py,第116行,__init__
self._connect = self._validate_timeout(connect,'connect')
文件/ usr / lib / python3 / dist-packages / urllib3 /util.py,第147行,在_validate_timeout
int或float。 %(name,value))
ValueError:超时值connect为(1,30),但它必须是一个int或float。

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

解决方案

这个错误是因为你的 urllib3 请求版本。您可以通过更新 urllib3 请求来解决问题:

  pip安装 - 升级urllib3请求

另一个解决方法是定义超时的自定义值,在应用程序的 AppConfig


$ b来自django.apps导入的AppConfig
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ '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)


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

解决方案

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中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆