[Flask] Having problem in send_file to client
lyc364
lyc364 at 163.com
Fri Sep 4 09:28:10 CEST 2015
Hi all,
I am building a very simple website where there is a download button. By clicking the button, the
user could download a specified file from my server.
Following is the html file in concern:
<h1><input type=button value=download onclick="window.location.href='download'">
and the code in server:
@app.route('/download')
def give_the_file():
if is_download:
file_name = apk_file_path + 'mini1_game_resign.apk'
is_download = False
return send_file(file_name, as_attachment = True, cache_timeout = 360)
The problem is: every time the user click the download button, the browser will trigger a dialog that let the user
choose where to save the file. At the moment the dialog appears, the server triggers exceptions:
Exception happened during processing of request from ('10.242.4.74', 41403)
Traceback (most recent call last):
File "C:\Python27\lib\SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python27\lib\SocketServer.py", line 657, in __init__
self.finish()
File "C:\Python27\lib\SocketServer.py", line 716, in finish
self.wfile.close()
File "C:\Python27\lib\socket.py", line 283, in close
self.flush()
File "C:\Python27\lib\socket.py", line 307, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10053]
The downloading can go without problem after the user saves the file because the server will receive another /download request.
Do you have any ideas on how this happened?
Thanks.
2015-09-04
lyc364
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20150904/f08e0ac9/attachment.html>
More information about the Flask
mailing list