Skip to content

Comment on Show HN: HTTP/2 Python-Asyncio Web Microframeworkparent

Comments

For the common pitfall question, when you do `await expression` python will resolve `expression` and then await it. When you do `await request.json()`, python calls `request.json()` and then awaits the return value (which will return json, at some point).

The same thing with `await request.data`. You can easily avoid this pitfall by writing this code:

    data = await resp.json()
    print(data['attribute'])
instead of this:
    print((await resp.json())['attribute'])
TBH I find that section of the docs more confusing than helpful, it's not an issue you'd generally run into IMO.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.