bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.38k stars 1.46k forks source link

Files with Certain Unicode Characters Don't Upload #852

Closed TimLudwinski closed 8 years ago

TimLudwinski commented 8 years ago

Client Code

>>> r = requests.post("http://server/upload", files={"file": (u'\u0412\u0430\u043b\u044e\u0442\u043d\u043e\u0435\u0437\u0430\u043a\u043e\u
043d\u043e\u0434\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u043e.\u0420\u0438\u0441\u043a\u0438\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u043a\u0438\
u0442\u0430\u043c\u043e\u0436\u0435\u043d\u043d\u043e\u0439\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438.doc', file_bytes)})

Server Code

@route("/upload", method='POST')
def upload():
    if request.files.file != "":
        data = request.files.file
    else:
        data = None

    if data is None:
        abort(400, "No file provided")

    return {"status": "success"}

Result:

>>> r.status_code
400
>>> r.text
'...No file provided..'
TimLudwinski commented 8 years ago

Using UWSGI.

eric-wieser commented 8 years ago

To be clear, the problem is with file names, not the files themselves?

TimLudwinski commented 8 years ago

Well, the application is told that there is no file in this case. Maybe I should be reporting this further upstream since it may not be strictly a bottle problem.

On Tuesday, May 24, 2016, Eric Wieser notifications@github.com wrote:

To be clear, the problem is with file names, not the files themselves?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/bottlepy/bottle/issues/852#issuecomment-221321867

eric-wieser commented 8 years ago

Let me clarify my question:

Files with Certain Unicode Characters Don't upload

Is this:

TimLudwinski commented 8 years ago

It's the first one. "Files with certain unicode characters in their name don't upload".

defnull commented 8 years ago

The requests urllib3 library uses extended header attributes, which I suspect cgi.FieldStorage does not understand.

Content-Disposition: form-data; name="file"; filename*=utf-8''%D0%92%D0%B0%D0%BB%D1%8E%D1%82%D0%BD%D0%BE%D0%B5%D0%B7%D0%B0%D0%BA%D0%BE%D0%BD%D0%BE%D0%B4%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%D1%81%D1%82%D0%B2%D0%BE.%D0%A0%D0%B8%D1%81%D0%BA%D0%B8%D0%BA%D0%BE%D1%80%D1%80%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%BA%D0%B8%D1%82%D0%B0%D0%BC%D0%BE%D0%B6%D0%B5%D0%BD%D0%BD%D0%BE%D0%B9%D1%81%D1%82%D0%BE%D0%B8%D0%BC%D0%BE%D1%81%D1%82%D0%B8.doc

I'm not really sure yet.

defnull commented 8 years ago

Confirmed. And it seems that werkzeug or the stdlib email library don't parse these either. Support for RFC 2231 seems to be rare.

defnull commented 8 years ago

https://github.com/shazow/urllib3/issues/900

defnull commented 8 years ago

Confirmed as a bug/misfeature in urllib3, which is used by requests. They are working on a fix.

I don't see an easy way to work around this issue other than not using requests/urllib3 for the moment.