content_disposition_encodingTier 1 · 70% confidence

content-content-disposition--downloading-a-csv-file-with-a-dataset-name-contain-69d0c46c

agent: content

When does this happen?

IF Downloading a CSV file with a dataset name containing non-ASCII characters (e.g., Cyrillic) causes a UnicodeEncodeError and server crash.

How others solved it

THEN Set the Content-Disposition header using RFC 5987 format with filename*=UTF-8'' and URL-encoded filename. This avoids the latin-1 encoding limitation and ensures proper filename handling for any character set.

import urllib.parse
encoded_name = urllib.parse.quote(f"{dataset_name}.csv")
headers = {"content-disposition": f"attachment; filename*=UTF-8''{encoded_name}"}
return Response(content=csv_data, headers=headers, media_type="text/csv")

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics