def _create_session(self, username, password):
    """Create HTTP session.

    Args:
      username (str): Timesketch username
      password (str): Timesketch password

    Returns:
      requests.Session: Session object.
    """
    session = requests.Session()
    session.verify = False  # Depending on SSL cert is verifiable
    try:
      response = session.get(self.host_url)
    except requests.exceptions.ConnectionError:
      return False
    # Get the CSRF token from the response
    soup = BeautifulSoup(response.text, 'html.parser')
    csrf_token = soup.find('input', dict(name='csrf_token'))['value']
    login_data = dict(username=username, password=password)
    session.headers.update({
        'x-csrftoken': csrf_token,
        'referer': self.host_url
    })
    _ = session.post('{0:s}/login/'.format(self.host_url), data=login_data)
    return session
def _create_session ( self , username , password ) : session = requests . Session ( ) session . verify = False try : response = session . get ( self . host_url ) except requests . exceptions . ConnectionError : return False soup = BeautifulSoup ( response . text , 'html.parser' ) csrf_token = soup . find ( 'input' , dict ( name = 'csrf_token' ) ) [ 'value' ] login_data = dict ( username = username , password = password ) session . headers . update ( { 'x-csrftoken' : csrf_token , 'referer' : self . host_url } ) _ = session . post ( '{0:s}/login/' . format ( self . host_url ) , data = login_data ) return session
Create HTTP session.

    Args:
      username (str): Timesketch username
      password (str): Timesketch password

    Returns:
      requests.Session: Session object.