def authenticate(self, email=None, password=None):
<EOL>if email is None:<EOL><INDENT>email = self.email<EOL><DEDENT>else:<EOL><INDENT>self.email = email<EOL><DEDENT>if password is None:<EOL><INDENT>password = self.__pass<EOL><DEDENT>else:<EOL><INDENT>self.__pass = password<EOL><DEDENT>if email is None:<EOL><INDENT>email = raw_input('<STR_LIT>')<EOL>self.email = email<EOL><DEDENT>if password is None:<EOL><INDENT>password = getpass.getpass()<EOL>self.__pass = password<EOL><DEDENT>self.__log('<STR_LIT>'.format(self.email))<EOL>self.__session = requests.Session()<EOL>self.__session.headers = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>self.last_request_time = time.time()<EOL>payload = {<EOL>'<STR_LIT>': email,<EOL>'<STR_LIT>': password<EOL>}<EOL>response = self.post('<STR_LIT>', data=payload, redirects=False)<EOL>response_url = response.url<EOL>if response.status_code == <NUM_LIT>:<EOL><INDENT>response_url = response.headers['<STR_LIT:location>']<EOL><DEDENT>endpoint = response_url.split('<STR_LIT:/>')[-<NUM_LIT:1>]<EOL>self.__log('<STR_LIT>'.format(response.status_code))<EOL>self.__log('<STR_LIT>'.format(response_url))<EOL>self.__log('<STR_LIT>'.format(str(response.cookies.keys())))<EOL>if '<STR_LIT>' in response.headers:<EOL><INDENT>self.__log('<STR_LIT>'.format(response.headers['<STR_LIT>']))<EOL><DEDENT>if '<STR_LIT>' in response.headers:<EOL><INDENT>self.__log('<STR_LIT>'.format(response.headers['<STR_LIT>']))<EOL><DEDENT>soup = BeautifulSoup(response.text, "<STR_LIT>")<EOL>errors = soup.find(id='<STR_LIT>')<EOL>if errors:<EOL><INDENT>errors = errors.text.strip()<EOL>errors = re.sub('<STR_LIT>', '<STR_LIT>', errors)<EOL>errors = re.sub('<STR_LIT>', '<STR_LIT>', errors)<EOL>if errors == '<STR_LIT>':<EOL><INDENT>errors = None<EOL><DEDENT><DEDENT>if errors is not None:<EOL><INDENT>raise AuthenticationError(errors)<EOL><DEDENT>if endpoint == '<STR_LIT>':<EOL><INDENT>raise AuthenticationError('<STR_LIT>')<EOL><DEDENT>return True<EOL>
Authenticate with LendingClub and preserve the user session for future requests.
This will raise an exception if the login appears to have failed, otherwise it returns True.

Since Lending Club doesn't seem to have a login API, the code has to try to decide if the login
worked or not by looking at the URL redirect and parsing the returned HTML for errors.

Parameters
----------
email : string
    The email of a user on Lending Club
password : string
    The user's password, for authentication.

Returns
-------
boolean
    True on success or throws an exception on failure.

Raises
------
session.AuthenticationError
    If authentication failed
session.NetworkError
    If a network error occurred