Skip to content

Example code from client quickstart not working #3376

Closed
@caliph007

Description

I hope I am not fully making a fool of myself.
I am not able to get to work the few lines of the client quickstart code:

import aiohttp
async with aiohttp.ClientSession() as session:
    async with session.get('http://httpbin.org/get') as resp:
        print(resp.status)
        print(await resp.text())

in Python 3.6. I get:

async with aiohttp.ClientSession() as session:
SyntaxError: invalid syntax

That I understand, because async became a reserved work in 3.7.
But the doc states as dependency Python 3.5.3+

in Python 3.7 I get:

async with aiohttp.ClientSession() as session:
SyntaxError: 'async with' outside async function

What am I doing wrong?
Thank you in advance.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions