[Python] Flask App Receives POST Data but Doesn't Update Excel File Data

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am building an attendance tracker using Flask as the backend and JavaScript (fetch API) in the frontend. The frontend sends attendance data to the Flask route /bulk_mark_attendance, and I can see the data in the browser console and Flask logs, but the data does not update in the Excel file.

    What could be causing the Excel file to not update, even though data is received successfully in Flask?
    Do I need to close the file differently or update it in another way?

    def save_attendance(section, student_name, status, additional_info=""):

    try:

    print(f"[DEBUG] Saving attendance: {section}, {student_name}, {status}, {additional_info}")

    sheet = client.open_by_key(ATTENDANCE_SHEETS[section]).get_worksheet(0)

    score = attendance_mapping.get(status, 0)

    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")



    sheet.append_row([timestamp, student_name, status, score, additional_info])

    print("[DEBUG] Successfully added to Google Sheets!")

    return True

    except Exception as e:

    print(f"[ERROR] Saving attendance: {e}")

    return False


    I Tried:
    Checked if the file is open → It is closed, so no file lock issue.
    Printed request.get_json() output → The data is received correctly.
    Verified the file path → The script and attendance.xlsx are in the same folder.
    Tried a different file → No changes are written to any file.

    Continue reading...

Compartilhe esta Página