0

I have a site that provides users with a download using send_file in Flask. It seems to work fine with Desktops but fails to send file on mobiles.

These are the logs when it works (From a desktop)

at=info method=POST path="/process/" host=www.musicseize.com request_id=1c7edff0-3ea6-4ab5-88f4-5b072fe4ebd6 fwd="196.53.41.11" dyno=web.1 connect=0ms service=13284ms status=200 bytes=1911 protocol=http
2017-04-26T20:19:57.284466+00:00 app[web.1]: tmp/[Lyrics] Tears In Heaven -  Eric Clapton.mp3
2017-04-26T20:19:57.418202+00:00 heroku[router]: at=info method=GET path="/download/%5BLyrics%5D%20Tears%20In%20Heaven%20-%20%20Eric%20Clapton.mp3/Tears%20In%20Heaven/?Submit=Download" host=www.musicseize.com request_id=3b241e25-ca2f-43da-b970-8956e6599ba3 fwd="196.53.41.11,66.249.93.201" dyno=web.1 connect=9ms service=111ms status=200 bytes=6700881 protocol=http

These are the logs when it fails on a mobile

2017-04-26T20:19:57.725040+00:00 heroku[router]: at=info method=GET path="/download/%5BLyrics%5D%20Tears%20In%20Heaven%20-%20%20Eric%20Clapton.mp3/Tears%20In%20Heaven/?Submit=Download" host=www.musicseize.com request_id=ec670402-d472-4872-9ed2-7f54c3e41203 fwd="196.53.41.11" dyno=web.1 connect=0ms service=13ms status=500 bytes=456 protocol=http
2017-04-26T20:19:57.716253+00:00 app[web.1]: tmp/[Lyrics] Tears In Heaven -  Eric Clapton.mp3
2017-04-26T20:19:57.722196+00:00 app[web.1]: [2017-04-26 20:19:57,717] ERROR in app: Exception on /download/[Lyrics] Tears In Heaven -  Eric Clapton.mp3/Tears In Heaven/ [GET]
2017-04-26T20:19:57.722198+00:00 app[web.1]: Traceback (most recent call last):
2017-04-26T20:19:57.722199+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
2017-04-26T20:19:57.722199+00:00 app[web.1]:     response = self.full_dispatch_request()
2017-04-26T20:19:57.722200+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
2017-04-26T20:19:57.722200+00:00 app[web.1]:     rv = self.handle_user_exception(e)
2017-04-26T20:19:57.722201+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
2017-04-26T20:19:57.722201+00:00 app[web.1]:     reraise(exc_type, exc_value, tb)
2017-04-26T20:19:57.722202+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2017-04-26T20:19:57.722202+00:00 app[web.1]:     raise value
2017-04-26T20:19:57.722203+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
2017-04-26T20:19:57.722203+00:00 app[web.1]:     rv = self.dispatch_request()
2017-04-26T20:19:57.722204+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2017-04-26T20:19:57.722204+00:00 app[web.1]:     return self.view_functions[rule.endpoint](**req.view_args)
2017-04-26T20:19:57.722205+00:00 app[web.1]:   File "/app/deploy.py", line 146, in download
2017-04-26T20:19:57.722205+00:00 app[web.1]:     return send_file(os.path.join('tmp', path), as_attachment=True, attachment_filename='{}.{}'.format(title, EXT))
2017-04-26T20:19:57.722206+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/helpers.py", line 549, in send_file
2017-04-26T20:19:57.722206+00:00 app[web.1]:     file = open(filename, 'rb')
2017-04-26T20:19:57.722240+00:00 app[web.1]: FileNotFoundError: [Errno 2] No such file or directory: '/app/tmp/[Lyrics] Tears In Heaven -  Eric Clapton.mp3'
2017-04-26T20:19:57.722346+00:00 app[web.1]: Exception on /download/[Lyrics] Tears In Heaven -  Eric Clapton.mp3/Tears In Heaven/ [GET]
2017-04-26T20:19:57.722346+00:00 app[web.1]: Traceback (most recent call last):
2017-04-26T20:19:57.722347+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
2017-04-26T20:19:57.722347+00:00 app[web.1]:     response = self.full_dispatch_request()
2017-04-26T20:19:57.722348+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
2017-04-26T20:19:57.722348+00:00 app[web.1]:     rv = self.handle_user_exception(e)
2017-04-26T20:19:57.722348+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
2017-04-26T20:19:57.722349+00:00 app[web.1]:     reraise(exc_type, exc_value, tb)
2017-04-26T20:19:57.722349+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2017-04-26T20:19:57.722349+00:00 app[web.1]:     raise value
2017-04-26T20:19:57.722350+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
2017-04-26T20:19:57.722350+00:00 app[web.1]:     rv = self.dispatch_request()
2017-04-26T20:19:57.722351+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2017-04-26T20:19:57.722351+00:00 app[web.1]:     return self.view_functions[rule.endpoint](**req.view_args)
2017-04-26T20:19:57.722352+00:00 app[web.1]:   File "/app/deploy.py", line 146, in download
2017-04-26T20:19:57.722352+00:00 app[web.1]:     return send_file(os.path.join('tmp', path), as_attachment=True, attachment_filename='{}.{}'.format(title, EXT))
2017-04-26T20:19:57.722353+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask/helpers.py", line 549, in send_file
2017-04-26T20:19:57.722356+00:00 app[web.1]:     file = open(filename, 'rb')
2017-04-26T20:19:57.722358+00:00 app[web.1]: FileNotFoundError: [Errno 2] No such file or directory: '/app/tmp/[Lyrics] Tears In Heaven -  Eric Clapton.mp3'

I feel that somehow Flask changes the path for download to FileNotFoundError: [Errno 2] No such file or directory: '/app/tmp/[Lyrics] Tears In Heaven - Eric Clapton.mp3'

The file is actually stored at tmp/[Lyrics] Tears In Heaven - Eric Clapton.mp3

Lakshay Kalbhor
  • 577
  • 3
  • 7
  • 19

0 Answers0