question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

send_file fails when filename contains unicode symbols

See original GitHub issue

Hi.

I’ve detected an issue with supporting unicode filenames in send_file. If send_file attempts to respond with utf-8 in http headers, the answer is empty, the log contains something like “http-headers should containbe latin-1”. I know that browser support IS A MESS, but it seems, that sending two filenames (filename= and filename*=) separated by semicolon should work.

I’d like this to be handled by flask or werkzeug. Will you accept such pull request?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:38 (22 by maintainers)

github_iconTop GitHub Comments

4reactions
keyancommented, Mar 9, 2015

Similar discussion has already happened regarding this observation. See the issue from requests to read more about the details, but the short of it is that HTTP headers are supposed to only accept latin-1 characters. Changing this behavior in flask or werkzeug would only cause issues and break running code by allowing requests to be sent in an unsupported encoding to webservers which expect to get latin-1.

Someone else can chime in if I am mistaken, but I think this can be closed.

Similar discussion: https://github.com/kennethreitz/requests/issues/1926 https://github.com/jakubroztocil/httpie/issues/212

2reactions
georgthegreatcommented, Mar 10, 2015

BTW, I’ve solved the problem by sending filename*=utf-8’blah’ header field. Works everywhere except for the IE <= 8.

Here is the snippet:

response = flask.make_response(flask.send_file(pdf_full_path))
response.headers["Content-Disposition"] = \
    "attachment; " \
    "filenane={ascii_filename};" \
    "filename*=UTF-8''{utf_filename}".format(
    ascii_filename="book.pdf",
    utf_filename=urlparse.quote(os.path.basename(pdf_full_path))
)

Looks like a more correct way of fixing this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Send files with Unicode characters in filename using requests ...
So python has to convert the string to a unicode object first. ... But the decode fails because the string isn't valid ascii....
Read more >
Erlang -- file
RawFilename is a filename not subject to Unicode translation, meaning that it can contain characters not conforming to the Unicode encoding expected from...
Read more >
File upload and download troubleshooting FAQs - Pega Support
You cannot upload files with names containing Unicode characters (multibyte) because of character set mismatch at the Operator System level ...
Read more >
Changes — Flask Documentation (2.2.x)
Old names for some send_file parameters have been removed. download_name replaces ... Using built-in RequestContext, unprintable Unicode characters in Host ...
Read more >
File names not recognised if cpinternal is UTF-8 and filename ...
Most ABL file operations fail on Windows if the filename or path contains extended characters and the client is running with -cpinternal ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found