def setup_wsse_handler(base_url, username, password, preempt = True):
"""
Configure urllib2 to try/use WSSE authentication, with a specific
`username` and `password` when visiting any page that have a given
`base_url`. Once this function has been called, all future requests
through urllib2 should be able to handle WSSE authentication.
"""
# Create a password manager
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
# Add username/password for domain defined by base_url
passman.add_password(None, base_url, username, password)
# Create the auth handler and install it in urllib2
authhandler = WSSEAuthHandler(passman, preempt = preempt)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
# Example of how to use without handlers
评论列表
文章目录