python-3.x 获取错误:ValueError:[TypeError(“'coroutine' object is not iterable”),TypeError('vars()argument must have __dict__attribute')]

new9mtju  于 2023-05-19  发布在  Python
关注(0)|答案(1)|浏览(1316)
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("\"","")
7cjasjjr

7cjasjjr1#

[TypeError(“'coroutine' object is not iterable”),TypeError('vars()argument must havedictattribute')]通常发生在开发人员使用异步函数时出错。
解决方法:添加'await'试试。

*asyncdef answer_question(**request.dict()):...

wait answer_question(QUERY,answer)
需要确保async函数包含db进程、会话管理、请求发送等,默认需要'await'。

相关问题