def _login_BA(self):
try:
# Creates a PasswordMgr instance
passmanager = urllib2.HTTPPasswordMgrWithDefaultRealm()
passmanager.add_password(None, self.url, self.username, self.password)
# Creates an auth handling object and builds it with opener
auth = urllib2.HTTPBasicAuthHandler(passmanager)
opener = urllib2.build_opener(auth)
response = opener.open(self.url, timeout=8)
data = response.read()
response.close()
return data
except Exception, e:
if 'Error 401' in str(e):
raise Exception('Login credentials incorrect.')
评论列表
文章目录