【发布时间】:2021-02-09 16:50:43
【问题描述】:
每当我尝试制作聊天机器人时 我选择使用端点
但我收到此错误 文件“/app/chatbot/plugins/response.py”,第 10 行 打印((等待get_response('世界'))) ^ SyntaxError: 'await' 外部函数
请帮助我,如果你能帮助我,我将非常感激
我的代码在哪里
import aiohttp
async def get_response(query):
async with aiohttp.ClientSession() as ses:
async with ses.get(
f'https://some-random-api.ml/chatbot?message={query}'
) as resp:
return (await resp.json())['response']
print((await get_response('world')))
【问题讨论】:
-
最后一行使用
awaitoutside 的async函数。你不能这样做。 -
我该如何解决??
标签: python python-3.x aiohttp