Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 589
Reda Drissi Avatar asked Jan 26 '23 03:01

Reda Drissi


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())
like image 57
Sraw Avatar answered Jan 28 '23 16:01

Sraw