Send user credentials in aiohttp request

Viewed 9150

I can't find a way to send user credentials with aiohttp. I want similar behavior to cURL's

curl --user "USER:PASSWORD"

but in aiohttp. On the reference doc I can't find this option, I can find query parameters, headers, body, but not user credentials.

I'm using aiohttp instead of curl for its asynchronous behavior.

1 Answers

It is the same as using basic authentication.

So to use it in aiohttp, you could use aiohttp.BasicAuth. Somehow like:

async with client.get(url, auth=aiohttp.BasicAuth(user, password)) as resp:
    assert resp.status == 200
    print(await resp.text())
Related