【发布时间】:2023-08-23 03:18:01
【问题描述】:
搞砸了 Python,我正在尝试使用这个 https://updates.opendns.com/nic/update?hostname=,当您访问该 URL 时,它会提示您输入用户名和密码。我一直在环顾四周,发现了一些关于密码管理器的东西,所以我想出了这个:
urll = "http://url.com"
username = "username"
password = "password"
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, urll, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
urllib2 = urllib2.build_opener(authhandler)
pagehandle = urllib.urlopen(urll)
print (pagehandle.read())
这一切都有效,但它通过命令行提示用户名和密码,需要用户的交互。我希望它自动输入这些值。我做错了什么?
【问题讨论】: