出现错误:ValueError:[TypeError(“'coroutine'对象不可迭代”),TypeError('vars()参数必须具有__dict__属性')]

问题描述 投票:0回答:1
async def answer_question(QUERY, answer):
    async with aiohttp.ClientSession() as session:
        response = await session.post('http://127.0.0.1:5009/answer', json={
            "question": QUERY,
            "passage": answer
        })
        return response.text.replace("\"","")
python-3.x elasticsearch
1个回答
2
投票

[TypeError("'coroutine' object is not iterable"), TypeError('vars() argument must have dict attribute')] 通常发生在开发人员使用异步函数时犯了错误。

解决方案:只需添加“await”即可尝试。

  • async def answer_question(**request.dict()): ...
    等待答案_问题(查询,答案)

应确保包含数据库进程、会话管理、请求发送等的async功能默认需要“await”。

© www.soinside.com 2019 - 2024. All rights reserved.