如何处理 aiohttp 响应中的表单数据

ala*_*ock 2 python multipartform-data aiohttp python-3.5

我正在寻找获取多部分表单数据并将其转换为字典。对于 json 来说很简单,但这似乎有点不同。

当前代码:

app = web.Application()

async def deploy(request):
    # retrieve multipart form data or
    # x-www-form-urlencoded data
    # convert to a dictionary if not already
    text = "Hello"
    return web.Response(text=text)
app.router.add_post('/', deploy)

web.run_app(app)
Run Code Online (Sandbox Code Playgroud)

Nic*_*ich 6

您可以使用该request.post()方法。

app = web.Application()

async def deploy(request):
    # retrieve multipart form data or
    # x-www-form-urlencoded data
    data = await request.post()
    print(data)
    text = "Hello"
    return web.Response(text=text)

app.router.add_post('/', deploy)

web.run_app(app)
Run Code Online (Sandbox Code Playgroud)

  • 惊人的。aiohttp 的文档示例有点薄弱。我希望这对将来的人有帮助。 (2认同)