Haystack / Whoosh 索引生成错误

发布于 2024-08-16 18:26:02 字数 2093 浏览 4 评论 0原文

我正在尝试使用 whoosh 后端设置 haystack 。当我尝试生成索引[或任何与此相关的索引命令]时,我收到:

TypeError: Item in ``from list'' not a string

如果我完全删除我的search_indexes.py,我会得到相同的错误[所以我猜测它根本找不到该文件]

可能会发生什么导致这个错误?它设置为自动发现,并且我确信我的应用程序已安装,因为我当前正在使用它。

完整回溯:

    Traceback (most recent call last):
  File "./manage.py", line 17, in <module>
    execute_manager(settings)
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 362, in execute_manager
    utility.execute()
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 257, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py", line 124, in <module>
    handle_registrations()
  File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py", line 121, in handle_registrations
    search_sites_conf = __import__(settings.HAYSTACK_SITECONF)
  File "/Users/ghostrocket/Development/Redux/website/../website/search_sites.py", line 2, in <module>
    haystack.autodiscover()
  File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py", line 83, in autodiscover
    app_path = __import__(app, {}, {}, [app.split('.')[-1]]).__path__
TypeError: Item in ``from list'' not a string

这是我的 search_indexes.py

from haystack import indexes
from haystack import site
from myproject.models import *

site.register(myobject)

I'm trying to setup haystack with whoosh backend. When i try to gen the index [or any index command for that matter] i receive:

TypeError: Item in ``from list'' not a string

if i completely remove my search_indexes.py i get the same error [so i'm guessing it can't find that file at all]

what might cause this error? it's set to autodiscover and i'm sure my app is installed because i'm currently using it.

Full traceback:

    Traceback (most recent call last):
  File "./manage.py", line 17, in <module>
    execute_manager(settings)
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 362, in execute_manager
    utility.execute()
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 257, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/core/management/__init__.py", line 67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Users/ghostrocket/Development/Redux/.dependencies/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py", line 124, in <module>
    handle_registrations()
  File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py", line 121, in handle_registrations
    search_sites_conf = __import__(settings.HAYSTACK_SITECONF)
  File "/Users/ghostrocket/Development/Redux/website/../website/search_sites.py", line 2, in <module>
    haystack.autodiscover()
  File "/Users/ghostrocket/Development/Redux/.dependencies/haystack/__init__.py", line 83, in autodiscover
    app_path = __import__(app, {}, {}, [app.split('.')[-1]]).__path__
TypeError: Item in ``from list'' not a string

and here is my search_indexes.py

from haystack import indexes
from haystack import site
from myproject.models import *

site.register(myobject)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眉目亦如画i 2024-08-23 18:26:03

您似乎遇到了两个问题。

第一个是生成 TypeError 的错误。当 Haystack 搜索您在 INSTALLED_APPS 中列出的每个应用程序以查找 search_indexes.py 时(因为您是自动注册),就会发生这种情况。我不确定问题到底是什么,但我首先在您的项目中搜索 from list 并仔细检查您的代码。我以前没有遇到过这种异常,但如果在您编写的代码中发生这种情况,您应该在问题中发布任何相关部分

我相信您在使用或不使用 search_indexes.py 文件时遇到相同错误的原因是因为它从未达到这一点尝试执行该文件中的代码。

也就是说,该文件中应该发生更多事情(这是第二个问题)。您必须创建一个索引类(继承自 haystack.indexes.SearchIndex)并将其注册到模型中。有关说明和示例,请参阅文档的此部分

由于作者和haystack 的其他用户会在那里看到它,并且他们往往会非常有帮助。

It seems like there are two problems you're running into.

The first is the one that's generating that TypeError. It occurs while Haystack is searching through each app you have listed in INSTALLED_APPS for a search_indexes.py (since you're auto-registering). I'm not sure exactly what the problem is, but I'd start by doing a search through your project for from list and double-checking your code. I haven't encountered that exception before, but if that's happening in code you wrote you should post any relevant sections in your question

I believe the reason you get the same error with or without the search_indexes.py file is because it never reaches the point of trying to execute the code in that file.

That said, there should be more happening in that file (which is the second problem). You have to create an index class (that inherits from haystack.indexes.SearchIndex) and register that with the model. See this section of the documentation for instructions and an example.

I'd also ask this question in the django-haystack Google Group since the author and other users of haystack will see it there and they tend to be extremely helpful.

阿楠 2024-08-23 18:26:03

昨晚我在一个 5 分钟前运行的代码库上遇到了同样的错误,没有进行任何类型的修改。
就我浏览我的 git 存储库而言,之前运行的代码导致了同样的错误。
我将 unicode 值转换为字符串,它消除了问题,但没有解决根本原因。

所以我发现如果:

  1. 它不是来自我的代码,
  2. 它是在 python 函数 import 中引发的
  3. ,我的 python 和代码库都没有改变,

问题必须出在位代码中。我删除了应用程序中的每个 .pyc 和 .pyo 文件。错误消失了。

删除 .py- 文件:

find . -name "*.pyc" -exec rm -f {} \;
find . -name "*.pyo" -exec rm -f {} \;

I bumped into the same error last night, on a codebase that was working 5 minutes before without any modification of any kind.
As far up as I went through my git repo, code that was working previously caused the same error.
I cast my unicode value to string and it removed the problem but did not solve the underlying cause.

So I figured out that if:

  1. it did not come from my code
  2. it was raised in python function import
  3. neither my python nor code base had changed

the problem had to be in the bit code. I deleted every .pyc and .pyo file in my application. And the error was gone.

deleting the .py- files:

find . -name "*.pyc" -exec rm -f {} \;
find . -name "*.pyo" -exec rm -f {} \;

我刚刚遇到了具有完全不同堆栈的相同 TypeError 消息。

对整个错误消息的搜索得到了两个结果:这个问题,以及 Python 的 import.c 的源代码。
因此,经过一番挖掘,我发现这个特定的错误是当 __import__ 内置函数传递一个不是字符串的导入名称时引起的。

重要的词是字符串 - 即。一个 str 对象。任何其他内容(例如 unicode)都将被拒绝,并出现此处描述的错误。

所以解决方案是:无论您将模块/成员名称传递给动态导入它的东西,请确保它是 str 而不是 unicode

失败:

__import__('mylib.foo', globals(), locals(), [u'bar'])

工作:

__import__('mylib.foo', globals(), locals(), ['bar'])
__import__(u'mylib.foo', globals(), locals(), ['bar'])

当然,这可能只与 Python 2.x 相关,因为 3.x 对字符串/unicode 的处理方式有所不同。

I've just encountered the same TypeError message with a completely different stack.

A search on the whole error message brought up two results: this question, and the source code for Python's import.c.
So after a little digging, I find that this particular error is caused when the __import__ builtin is passed an import name which isn't a string.

The important word there is string - ie. a str object. Anything else (eg. unicode) will be rejected with the error described here.

So the solution is: wherever you're passing a module/member name to something which will dynamically import it, make sure that it's a str and not a unicode.

Fails:

__import__('mylib.foo', globals(), locals(), [u'bar'])

Work:

__import__('mylib.foo', globals(), locals(), ['bar'])
__import__(u'mylib.foo', globals(), locals(), ['bar'])

Of course, this is probably only relevant to Python 2.x, given that 3.x does strings/unicode differently.

沫离伤花 2024-08-23 18:26:02

就我而言,这是在我将 django-tastypie 升级到 v0.10 后发生的。作为 Py3 移植工作的一部分,from __future__ import unicode_literals 被添加到迁移的顶部。

在每个 tastypie 迁移文件中注释掉该行后,我的迁移运行正常。

让我感到困惑的是,昨天,tastypie 迁移在新的 tastypie 版本上运行正常(在共享相同 virtualenv 的单独项目中)。这将是一个谜。

In my case, this occurred after I upgraded my django-tastypie to v0.10. As part of the Py3 porting effort, from __future__ import unicode_literals was added to the top of the migrations.

After commenting that line out in each of the tastypie migrations files, my migrations have run OK.

What I find puzzling is the fact that the tastypie migrations ran OK yesterday with the new tastypie version ( in a separate project that shares the same virtualenv ). That is a mystery for another day.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文