url = 'http://www.example.com'
username = 'bob'
password = 'pass123'
password_store = urllib.request.HTTPPasswordMgrWithDefaultRealm()
password_store.add_password(None, url, username, password)
passwords = urllib.request.HTTPBasicAuthHandler(password_store)
opener = urllib.request.build_opener(passwords)
resp = opener.open(url)
resp.read()
Programmatically Provide Secondary WiFi HotSpot Credentials with Python on Linux