Ejemplo n.º 1
0
def authenticate_with_server():
    http_session = requests.session()
    http_session.get(LOGIN_PAGE, headers=HEADER)
    data = {"pseudo": USERNAME, "passe": PASSWORD, "souvenir": 1}
    http_session.post(POST_LOGIN_PAGE, data, headers=HEADER)
    logger.warning('LOGIN')
    save_session_in_cache(http_session)
    save_session_to_db()
    return http_session
Ejemplo n.º 2
0
def __generic_request(method_name, address, post_data=None):
    http_session = get_session()
    if not http_session:
        logger.warning('No previous session found')
        http_session = authenticate_with_server()
    result = getattr(http_session, method_name)(address, data=post_data, headers=constants.HEADER).text
    if not is_connected(result):
        logger.warning('Session expired')
        http_session = authenticate_with_server()
        try:
            result = getattr(http_session, method_name)(address, data=post_data, headers=constants.HEADER).text
        except:
            wait()
            result = getattr(http_session, method_name)(address, data=post_data, headers=constants.HEADER).text
    save_session_in_cache(http_session)
    wait()
    return result