运行"./manage.py rebuild_index"时出现django-haystack错误

0 投票
1 回答
858 浏览
提问于 2025-04-18 07:29

我在运行时遇到了下面的类型错误:

python manage.py rebuild_index

我现在的环境是 Solr 4.8.1、django-haystack 2.1.0、Django 1.6.2 和 Python 3.4.0。

有没有人知道这可能是什么原因造成的?以下是错误的详细信息:

ERROR:root:Error updating blog using default 
Traceback (most recent call last):
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
    self.update_backend(label, using)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 267, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
    backend.update(index, current_qs)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/backends/solr_backend.py", line 68, in update
    self.conn.add(docs, commit=commit, boost=index.get_field_weights())
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 779, in add
    return self._update(m, commit=commit, waitFlush=waitFlush, waitSearcher=waitSearcher)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 387, in _update
    return self._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'})
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 318, in _send_request
    error_message = self._extract_error(resp)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 397, in _extract_error
    reason, full_html = self._scrape_response(resp.headers, resp.content)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 467, in _scrape_response
    full_html = full_html.replace('\n', '')
TypeError: expected bytes, bytearray or buffer compatible object
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/management/commands/rebuild_index.py", line 16, in handle
    call_command('update_index', **options)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/django/core/management/__init__.py", line 159, in call_command
    return klass.execute(*args, **defaults)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 195, in handle
    return super(Command, self).handle(*items, **options)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/django/core/management/base.py", line 385, in handle
    label_output = self.handle_label(label, **options)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
    self.update_backend(label, using)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 267, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
    backend.update(index, current_qs)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/haystack/backends/solr_backend.py", line 68, in update
    self.conn.add(docs, commit=commit, boost=index.get_field_weights())
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 779, in add
    return self._update(m, commit=commit, waitFlush=waitFlush, waitSearcher=waitSearcher)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 387, in _update
    return self._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'})
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 318, in _send_request
    error_message = self._extract_error(resp)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 397, in _extract_error
    reason, full_html = self._scrape_response(resp.headers, resp.content)
  File "/Users/aaron/Documents/virtualenvs/three/lib/python3.4/site-packages/pysolr.py", line 467, in _scrape_response
    full_html = full_html.replace('\n', '')
TypeError: expected bytes, bytearray or buffer compatible object

1 个回答

0

在我的情况下,出现了一个关于 django_id 的问题。对我有帮助的是 这个 问题。我做了以下几件事:

  • 把模式文件放到 solr-x.y.z/example/solr/collection1/conf/schema.xml 这个位置。

  • fields 部分给模式添加一个版本字段(如下所述):

<field name="django_id" type="string" indexed="true" stored="true" multiValued="false"/>

撰写回答