Problem
Sometimes you might want to authenticate against an API with username and password where examples are only listed with curl:
curl -u username:password https://127.0.0.1/foobar
Solution
If you want to implement the same in python you can use the following
import requests
from requests.auth import HTTPBasicAuth
username = "username"
password = "password"
request_url = "https://127.0.0.1/foobar"
result = requests.post(request_url, auth=HTTPBasicAuth(username, password))
Hope it helps, let me know
[amazon_link asins=’1449355730′ template=’ProductAd‘ store=’a_blog-21′ marketplace=’DE‘ link_id=’1f5fc7fe-d1d5-11e8-a5e0-9967f08ec3e0′]