def http_auth_request(url, host, user, passwd, user_agent=USER_AGENT):
"""Call an HTTP server with authorization credentials using urllib2.
"""
if DEBUG: httplib.HTTPConnection.debuglevel = 1
# Hook up handler/opener to urllib2
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, host, user, passwd)
auth_handler = urllib2.HTTPBasicAuthHandler(password_manager)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
return http_request(url, user_agent)
评论列表
文章目录