import requests
from requests.auth import HTTPBasicAuth
requests.get('URL', auth=HTTPBasicAuth('username', 'password'))
#or
import base64
requests.get('URL', headers={"Authorization":"Basic %s" % base64.b64encode("username:password".encode("ascii"))}) # when base 64 encoding is required
import requests
requests.get("URL",headers={"Authorization":"Bearer %s" % token})
url='http://www.google.com/blahblah'
try:
r = requests.get(url,timeout=3)
r.raise_for_status()
except requests.exceptions.RequestException as err:
print ("OOps: Something Else",err)
except requests.exceptions.HTTPError as errh:
print ("Http Error:",errh)
except requests.exceptions.ConnectionError as errc:
print ("Error Connecting:",errc)
except requests.exceptions.Timeout as errt:
print ("Timeout Error:",errt)