def authenticate(self):
valid = self._session_check()<EOL>if self._is_authenticated and valid:<EOL><INDENT>self._log.debug("<STR_LIT>")<EOL>return<EOL><DEDENT>init = self._session.get(url=self.LOGIN_URL, headers=self.HEADERS)<EOL>soup = BeautifulSoup(init.content, "<STR_LIT>")<EOL>soup_login = soup.find('<STR_LIT>').find_all('<STR_LIT:input>')<EOL>post_data = dict()<EOL>for u in soup_login:<EOL><INDENT>if u.has_attr('<STR_LIT:name>') and u.has_attr('<STR_LIT:value>'):<EOL><INDENT>post_data[u['<STR_LIT:name>']] = u['<STR_LIT:value>']<EOL><DEDENT><DEDENT>post_data['<STR_LIT>'] = self._email<EOL>post_data['<STR_LIT>'] = self._password<EOL>response = self._session.post(url=self.AUTH_URL, data=post_data,<EOL>headers=self.HEADERS)<EOL>if self.CAPTCHA_KEY in str(response.content):<EOL><INDENT>raise AccountCaptcha('<STR_LIT>')<EOL><DEDENT>cookies = [x.name for x in response.cookies]<EOL>if '<STR_LIT>' not in cookies:<EOL><INDENT>raise InvalidCredentials("<STR_LIT>")<EOL><DEDENT>with open(SESSION_FILE, '<STR_LIT:wb>') as f:<EOL><INDENT>cookies = requests.utils.dict_from_cookiejar(self._session.cookies)<EOL>pickle.dump(cookies, f, protocol=<NUM_LIT:2>)<EOL>self._log.debug("<STR_LIT>")<EOL><DEDENT>self._log.debug("<STR_LIT>")<EOL>self._is_authenticated = True<EOL>self._process_state()<EOL>return<EOL>
Authenticate the user and setup our state.