Basic authentication not working with Requests library
You need to use a session object and send the authentication each request. The session will also track cookies for you:
session = requests.Session()
session.auth = (user, password)
auth = session.post('http://' + hostname)
response = session.get('http://' + hostname + '/rest/applications')
import requests
from requests.auth import HTTPBasicAuth
res = requests.post('https://api.github.com/user', verify=False, auth=HTTPBasicAuth('user', 'password'))
print (res)
Note: sometimes, we may get SSL error certificate verify failed, to avoid, we can use verify=False