mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
mgr.add_password(None, url, user, password)
urllib.request.build_opener(urllib.request.HTTPBasicAuthHandler(mgr), urllib.request.
    HTTPDigestAuthHandler(mgr))
Python Authentication with urllib2