import requests

# Canvas configuration
CANVAS_BASE_URL = 'https://canvas.nus.edu.sg'
COURSE_ID = '63926'
QUIZ_ID = '46047'
ACCESS_TOKEN = "21450~wkYwhrMwh2ELTLF2n7wAzrUDMwQfQDuYHDM2X3BrGJX9mUZH44NW8yHMkBBmk9FB"

headers = {
    'Authorization': f'Bearer {ACCESS_TOKEN}'
}

def begin_quiz_submission():
    url = f'{CANVAS_BASE_URL}/api/v1/courses/{COURSE_ID}/quizzes/{QUIZ_ID}/submissions'
    try:
        response = requests.post(url, headers=headers)
        response.raise_for_status()
        data = response.json()
        quiz_submission = data['quiz_submissions'][0]
        return quiz_submission['id'], quiz_submission['validation_token']
    except requests.exceptions.HTTPError as http_err:
        print(f'HTTP error occurred: {http_err}')  # Handle errors appropriately
    except Exception as err:
        print(f'An error occurred: {err}')


def get_quiz_questions(quiz_submission_id):
    url = f'{CANVAS_BASE_URL}/api/v1/quiz_submissions/{quiz_submission_id}/questions'
    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        data = response.json()
        questions = data['quiz_questions']
        return questions
    except requests.exceptions.HTTPError as http_err:
        print(f'HTTP error occurred: {http_err}')
    except Exception as err:
        print(f'An error occurred: {err}')


def submit_answers(quiz_submission_id, validation_token, answers):
    url = f'{CANVAS_BASE_URL}/api/v1/quiz_submissions/{quiz_submission_id}/questions'
    payload = {
        'quiz_questions': answers,
        'validation_token': validation_token
    }
    try:
        response = requests.post(url, headers=headers, json=payload)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.HTTPError as http_err:
        print(f'HTTP error occurred: {http_err}')
    except Exception as err:
        print(f'An error occurred: {err}')

def complete_quiz_submission(quiz_submission_id, validation_token):
    url = f'{CANVAS_BASE_URL}/api/v1/courses/{COURSE_ID}/quizzes/{QUIZ_ID}/submissions/{quiz_submission_id}/complete'
    payload = {
        'validation_token': validation_token
    }
    try:
        response = requests.post(url, headers=headers, data=payload)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.HTTPError as http_err:
        print(f'HTTP error occurred: {http_err}')
    except Exception as err:
        print(f'An error occurred: {err}')

def main():
    # Step 1: Begin Quiz Submission
    print("Starting quiz submission...")
    result = begin_quiz_submission()
    if not result:
        print("Failed to start the quiz submission.")
        return
    quiz_submission_id, validation_token = result
    print(f"Quiz Submission ID: {quiz_submission_id}")
    print(f"Validation Token: {validation_token}")

    # Step 2: Get Quiz Questions
    print("Retrieving quiz questions...")
    questions = get_quiz_questions(quiz_submission_id)
    if not questions:
        print("Failed to retrieve quiz questions.")
        return
    print(f"Retrieved {len(questions)} questions.")

    # Prepare answers (This should be based on your logic or user inputs)
    # Here's a dummy example where we select the first option for multiple-choice questions
    answers = []
    for question in questions:
        answer = {'id': question['id']}
        if question['question_type'] == 'multiple_choice_question':
            # Select the first answer choice
            answer['answer'] = question['answers'][0]['id']
        elif question['question_type'] == 'true_false_question':
            answer['answer'] = True  # Replace with actual logic
        else:
            # Add handling for other question types as needed
            answer['answer'] = ''  # Placeholder
        answers.append(answer)

    # Step 3: Submit Answers
    print("Submitting answers...")
    submit_response = submit_answers(quiz_submission_id, validation_token, answers)
    if not submit_response:
        print("Failed to submit answers.")
        return
    print("Answers submitted.")

    # Step 4: Complete Quiz Submission
    print("Completing quiz submission...")
    complete_response = complete_quiz_submission(quiz_submission_id, validation_token)
    if not complete_response:
        print("Failed to complete quiz submission.")
        return
    print("Quiz submission completed successfully.")

if __name__ == "main":
    main()

How can I test if the endpoint is working properly.