@docs_bp.route('/api/download-doc', methods=['POST'])
def download_word():
    data = request.get_json()
    cursor_and_connection = get_cursor_and_connection()

    word_header = ''

    # Проверка на id
    if data['id'] == 0:
        word_header = 'Все товары'
        cursor_and_connection['cursor'].execute("""
            SELECT
                prod.name as "Название",
                prod.quantity as "В наличии",
                prod.insurance as "Критический запас",
                prod.shelf as "Полка",
                assort.purchase_cost as "Закупочная цена",
                prod.cost as "Цена продажи",
                sup.name as "Поставщик"
            FROM Product prod
            LEFT JOIN Assortment assort ON assort.product_id = prod.id
            LEFT JOIN Supplier sup ON assort.supplier_id = sup.id;""")
    elif data['id'] == 1:
        word_header = 'Товары в наличии'
        cursor_and_connection['cursor'].execute("""
        SELECT
            prod.name as "Название",
            prod.quantity as "В наличии",
            prod.insurance as "Критический запас",
            prod.shelf as "Полка",
            assort.purchase_cost as "Закупочная цена",
            prod.cost as "Цена продажи",
            sup.name as "Поставщик"
        FROM Product prod
        LEFT JOIN Assortment assort ON assort.product_id = prod.id
        LEFT JOIN Supplier sup ON assort.supplier_id = sup.id
        WHERE prod.quantity > 0;
        """)
    elif data['id'] == 2:
        cursor_and_connection['cursor'].execute("""
                SELECT
                    prod.name as "Название",
                    prod.quantity as "В наличии",
                    prod.insurance as "Критический запас",
                    prod.shelf as "Полка",
                    assort.purchase_cost as "Закупочная цена",
                    prod.cost as "Цена продажи",
                    sup.name as "Поставщик"
                FROM Product prod
                LEFT JOIN Assortment assort ON assort.product_id = prod.id
                LEFT JOIN Supplier sup ON assort.supplier_id = sup.id
                WHERE prod.quantity <= prod.insurance;
                """)
    elif data['id'] == 3 and data['supplier_id']:
        cursor_and_connection['cursor'].execute("""
                        SELECT
                            prod.name as "Название",
                            prod.quantity as "В наличии",
                            prod.insurance as "Критический запас",
                            prod.shelf as "Полка",
                            assort.purchase_cost as "Закупочная цена",
                            prod.cost as "Цена продажи",
                            sup.name as "Поставщик"
                        FROM Product prod
                        LEFT JOIN Assortment assort ON assort.product_id = prod.id
                        LEFT JOIN Supplier sup ON assort.supplier_id = sup.id
                        WHERE sup.id = %s;
                        """, (data['supplier_id'],))
    else:
        close_cursor_and_connection(cursor_and_connection)
        return jsonify({'message': 'Неверный id'}), 400

    products = cursor_and_connection['cursor'].fetchall()
    close_cursor_and_connection(cursor_and_connection)

    if not products:
        return jsonify({'message': 'Товары не найдены'}), 200

    if data['doc_type'] == 'excel':
        df = pd.DataFrame(products, columns=["Название", "В наличии", "Критический запас", "Полка", "Закупочная цена",
                                             "Цена продажи", "Поставщик"])
        output = BytesIO()
        df.to_excel(output, index=False, engine='openpyxl')
        output.seek(0)
        return send_file(output, as_attachment=True, download_name='Все товары.xlsx',
                         mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')

    elif data['doc_type'] == 'word':
        doc = Document()
        doc.add_heading(word_header, level=1)

        # Создание таблицы в документе Word
        table = doc.add_table(rows=1, cols=7)
        table.style = 'Table Grid'

        # Добавление заголовков таблицы
        hdr_cells = table.rows[0].cells
        hdr_cells[0].text = 'Название'
        hdr_cells[1].text = 'В наличии'
        hdr_cells[2].text = 'Критический запас'
        hdr_cells[3].text = 'Полка'
        hdr_cells[4].text = 'Закупочная цена'
        hdr_cells[5].text = 'Цена продажи'
        hdr_cells[6].text = 'Поставщик'

        # Добавление данных в таблицу
        for product in products:
            row_cells = table.add_row().cells
            row_cells[0].text = str(product[0])
            row_cells[1].text = str(product[1])
            row_cells[2].text = str(product[2])
            row_cells[3].text = str(product[3])
            row_cells[4].text = str(product[4])
            row_cells[5].text = str(product[5])
            row_cells[6].text = str(product[6])

        output = BytesIO()
        doc.save(output)
        output.seek(0)
        return send_file(output, as_attachment=True, download_name='Все товары.docx',
                         mimetype='application/vnd.openxmlformats-officedocument.wordprocessingml.document')

    return jsonify({'message': 'Неверный тип документа'}), 400

Мне пишут, что файл поврежден или не соответствует расширению