def __init__(self, username, password): password_mgr = HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, self.posturl, username, password) auth_handler = HTTPBasicAuthHandler(password_mgr) self.ua = UserAgent(handlers=[auth_handler])