password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
top_level_url = 'http://example.com/foo/'
password_mgr.add_password(None, top_level_url, username, password)
handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
opener = urllib.request.build_opener(handler)
opener.open(a_url)
urllib.request.install_opener(opener)
подключиться к URL-адресу в python