TypeError: ‘async for’ requires an object with __aiter__ method

用户在 RAGFlow 中添加 WebDAV 服务器(OnlyOffice)作为数据源,连接测试通过,但在数据导入(ingestion)过程中触发报错。

TypeError: 'async for' requires an object with __aiter__ method

TypeError: ‘async for’ requires an object with __aiter__ method, got generator

快速结论:该报错通常发生在 RAGFlow 通过 WebDAV(OnlyOffice)连接器同步数据源时,返回了一个同步生成器,但数据摄入逻辑使用了 async for 迭代。优先更新到包含 PR #12405 修复的版本,或使用 nightly Docker 镜像。

问题场景

用户在 RAGFlow 中添加 WebDAV 服务器(OnlyOffice)作为数据源,连接测试通过,但在数据导入(ingestion)过程中触发报错。

报错原文

TypeError: 'async for' requires an object with __aiter__ method, got generator
Traceback (most recent call last):
  File "/ragflow/rag/svr/sync_data_source.py", line 82, in __call__
    await asyncio.wait_for(self._run_task_logic(task), timeout=task["timeout_secs"])
  File "/usr/lib/python3.12/asyncio/tasks.py", line 520, in wait_for
    return await fut
           ^^^^^^^^^
  File "/ragflow/rag/svr/sync_data_source.py", line 113, in _run_task_logic
    async for document_batch in document_batch_generator:
TypeError: 'async for' requires an object with __aiter__ method, got generator

原因分析

这是一个已知问题。RAGFlow 的 WebDAV(OnlyOffice)连接器返回的是同步生成器(synchronous generator),但 sync_data_source.py 中的 _run_task_logic 方法使用了 async for 进行迭代,而 async for 仅支持异步可迭代对象(带有 __aiter__ 方法),因此报错。

环境排查

  • RAGFlow 版本:需要确认是否早于 PR #12405 合并日期(2026-01-04)的版本。
  • Python 版本:报错中显示为 Python 3.12,但问题与 Python 版本无关。
  • 数据源类型:WebDAV (OnlyOffice) 连接器。

解决步骤

  1. 优先尝试更新 RAGFlow 版本:升级到包含 PR #12405 修复的版本,该修复将 async for 改为常规 for 循环来遍历同步生成器。合并日期为 2026-01-04。
  2. 使用 nightly Docker 镜像:如果无法立即升级到正式版本,可以先使用 nightly 构建的 Docker 镜像(根据用户反馈,nightly 版本可以正常工作)。
  3. 旧版本临时修复(仅限开发者):如果必须修补旧版本,可以在连接器代码中将同步生成器包装为异步包装器,例如:
    async def async_wrapper(sync_gen):
        for batch in sync_gen:
            yield batch
    # 然后返回 async_wrapper(document_batch_generator)

注意:不存在仅通过配置文件修复的方法,需要更新代码或 Docker 镜像。

验证方法

重新启动 RAGFlow 的 WebDAV 数据同步任务(ingestion),观察不再出现 TypeError: 'async for' requires an object with __aiter__ method 报错,且数据能够正常导入。

参考来源

infiniflow/ragflow #12850

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 11394

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注