[Flask] Having problem in send_file to client
Federico Delgado Doyle
fededelgado at outlook.com
Sat Sep 5 02:19:25 CEST 2015
Hi,
>From what I see, the first request is abruptly cancelled by the client (your browser) and the socket server is trying to flush the contents of the response to a socket that is not good anymore. I do not have download code to test if I see the same text. What version of Python are you using?
Is your client code calling a page and in the middle of it redirecting to /download or something like that?
Date: Fri, 4 Sep 2015 15:28:10 +0800
From: lyc364 at 163.com
To: flask at python.org
Subject: [Flask] Having problem in send_file to client
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
_______________________________________________
Flask mailing list
Flask at python.org
https://mail.python.org/mailman/listinfo/flask
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20150904/16b86138/attachment-0001.html>
More information about the Flask
mailing list