Unable to zip files

javascript = os.path.join(settings.BASE_DIR, 'games/download/js_file.js')
            
        css = os.path.join(settings.BASE_DIR, 'games/download/css_file.css')
            
        empty = os.path.join(settings.BASE_DIR, 'games/download/css_file.js')
        
        import zipfile
        import io
        
        filenames = [javascript , css]
        zip_subdir = "zip files"
        zip_file = f"{zip_subdir}.zip"
        
        string = io.StringIO()
        zip = zipfile.ZipFile(string,"w", zipfile.ZIP_DEFLATED)
        
        for file_path in filenames:
            file_name = os.path.basename(file_path)
            zip_path = os.path.join(zip_subdir, file_name)
            
        zip.write(file_path, zip_path)
        zip.close()

While trying to zip some converted files… i keep getting an error at zip.write(file_path, zip_path) saying :

string argument expected, got ‘bytes’

Hi, not a django related issue.

You’d rather use io.BytesIO instead of io.StringIO.

If this change does not work, please share the full traceback of the error.