Check if a session is still available before sending messages:
Copy
try: session = get_session(session_id) if session['status'] not in ['error', 'terminated']: send_message(session_id, "Continue task...")except requests.HTTPError as e: if e.response.status_code == 404: print("Session no longer exists")