RuntimeError: this event loop is already running

十年热恋 提交于 2019-11-28 13:05:36

Here is the code that worked for me in sanic

@app.route('/upload')
async def get_ressource(request):
    asyncio.ensure_future(blocking_function())
    return await resp()

async def blocking_function():
    async with aiohttp.ClientSession() as session:
        async with session.post("your_url", data={
            'image': open("file_path", "rb"),
        }, headers={
            'Authorization': 'Client-ID {}'.format("your_client_id")
        }) as resp:
            result = await resp.text()
    print(result)


async def resp():
    return response.json("OK", status=202)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!