forked from xiyouMc/PythonGuide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckPwd.py
More file actions
29 lines (19 loc) · 818 Bytes
/
CheckPwd.py
File metadata and controls
29 lines (19 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys,urllib,urllib2,getpass
class TerminalPwd(urllib2.HTTPPasswordMgr):
def find_user_password(self,realm,authuri):
retval = urllib2.HTTPPasswordMgr.find_user_password(self,realm,authuri)
if retval[0] == None and retval[1] == None:
#didn't find it in stored values
username = input("Login required,please input username:")
password = input("please input password:")
return(username,password)
else:
return retval
url = "http://home.asiainfo.com/"
req = urllib2.Request(url)
opener = urllib2.build_opener(urllib2.HTTPBasicAuthHandler(TerminalPwd()))
fd = opener.open(req)
print ("URL Retrieved:",fd.geturl())
info = fd.info()
for key, value in info.items():
print "%s = %s" % (key,value)