Reda Drissi
Reda Drissi

Reputation: 1672

Send user credentials in aiohttp request

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.

Upvotes: 13

Views: 22493

Answers (1)

Sraw
Sraw

Reputation: 20224

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())

Upvotes: 25

Related Questions