How do I fix this aspose-pdf-cloud-python script to successfully download a processed PDF file from aspose storage?

How do I fix this aspose-pdf-cloud-python script to successfully download a processed PDF file from aspose storage?
Environment:

  • Windows 11 23H2;
  • Python 3.11.4;
import os
from asposepdfcloud import PdfApi, models
from asposepdfcloud.api_client import ApiClient

# Replace with your Aspose Cloud App key and App SID
app_key = 'app_key personal'
app_sid = 'app_sid personal'

# Initialize the PdfApi client
pdf_api_client = ApiClient(app_key=app_key, app_sid=app_sid)
pdf_api = PdfApi(pdf_api_client)

def process_pdf_files_in_folder(input_folder, output_folder):
    # Ensure the output folder exists
    os.makedirs(output_folder, exist_ok=True)

    # Iterate over all PDF files in the input folder
    for filename in os.listdir(input_folder):
        if filename.endswith(".pdf"):
            input_file_path = os.path.join(input_folder, filename)
            remote_name = filename
            copied_file = f'processed_{filename}'
            
            # Upload PDF file to cloud storage
            pdf_api.upload_file(remote_name, input_file_path)

            # Copy the file
            pdf_api.copy_file(remote_name, copied_file)

            # Replace text
            text_replace = models.TextReplace(old_value='Watermark instead', new_value='', regex=True)
            text_replace_list = models.TextReplaceListRequest(text_replaces=[text_replace])
            pdf_api.post_document_text_replace(copied_file, text_replace_list)
            
            # Download the processed file to the local system
            output_file_path = os.path.join(output_folder, copied_file)
            
            # Retrieve the file content from the cloud
            response = pdf_api.download_file(copied_file)
            
            # Open a file stream to write the downloaded content
            with open(output_file_path, 'wb') as file:
                # Write the content to the file
                file.write(response)

            print(f'Processed and saved: {output_file_path}')

# Use specific folder paths
process_pdf_files_in_folder(r'D:input', r'D:output')

The error when running the code is as follows:

D:>python rm.py
host: https://api.aspose.cloud/v3.0
tokenUrl: https://api.aspose.cloud/connect/token
Traceback (most recent call last):
  File "D:rm.py", line 49, in <module>
    process_pdf_files_in_folder(r'D:input', r'D:output')
  File "D:rm.py", line 44, in process_pdf_files_in_folder
    file.write(response)
TypeError: a bytes-like object is required, not 'str'

Multiple modify to the code still don’t work, need a runnable code.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật