1

I'm using Flask, mod_wsgi and Apache

When I try to download file which larger than 2GB, I got this message from error logs

[Sat Jul 23 17:04:05 2016] [error] [client 166.104.211.47] mod_wsgi (pid=11964): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.py'., referer: http://14.39.80.234/movie/
[Sat Jul 23 17:04:05 2016] [error] [client 166.104.211.47] ValueError: invalid content length, referer: http://14.39.80.234/movie/

How can I extend the download size limitation? I know that there is wsgi.filewrapper() but I don't know how to use it.

This is my alias script

#!/usr/local/bin/python2.7

import sys
sys.stderr.write('\n'.join(sorted(sys.path)) + '\n')
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/")
activate_this = '/var/www/FlaskApp/FlaskApp/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

from FlaskApp import app as application
application.secret_key = 'your secret key. If you share your website, do NOT share it with this key.'

This is 'activate_this.py'

"""By using execfile(this_file, dict(__file__=this_file)) you will
activate this virtualenv environment.

This can be used when you must use an existing Python interpreter, not
the virtualenv bin/python
"""

try:
    __file__
except NameError:
    raise AssertionError(
        "You must run this like execfile('path/to/activate_this.py', dict(__file__='path/to/activate_this.py'))")
import sys
import os

old_os_path = os.environ.get('PATH', '')
os.environ['PATH'] = os.path.dirname(os.path.abspath(__file__)) + os.pathsep + old_os_path
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if sys.platform == 'win32':
    site_packages = os.path.join(base, 'Lib', 'site-packages')
else:
    site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
prev_sys_path = list(sys.path)
import site
site.addsitedir(site_packages)
sys.real_prefix = sys.prefix
sys.prefix = base
# Move the added items to the front of the path:
new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:
        new_sys_path.append(item)
        sys.path.remove(item)
sys.path[:0] = new_sys_path

Please help me!

bsjun
  • 37
  • 1
  • 8
  • Why not have Apache serve it up as a static file directly? Serving up a file that large from Python is generally a bad idea. Anyway, include the actual code from your application showing how you are currently trying to serve up the static file and can then perhaps suggest something using ``wsgi.file_wrapper``. What access you have to that depends on the framework you are using. – Graham Dumpleton Jul 24 '16 at 04:25
  • @GrahamDumpleton How can I serve it directly from Apache? I only host web server using Flask.. I can't handle this problem whole day.. I want to know how to use wsgi.file_wrapper too. Should I edit the werkzeug/wrappers.py ? – bsjun Jul 25 '16 at 12:44
  • The documentation describes how to configure Apache for static files when using mod_wsgi. See http://modwsgi.readthedocs.io/en/develop/user-guides/configuration-guidelines.html#hosting-of-static-files As to ``wsgi.file_wrapper``, if using Werkzeug, you likely need to use its inbuilt feature for accessing it so see their documentation. Otherwise see the documentation at http://modwsgi.readthedocs.io/en/develop/user-guides/file-wrapper-extension.html Can't remember if still has 2GB limit though. – Graham Dumpleton Jul 25 '16 at 22:28
  • @GrahamDumpleton Is there ANY way to increase this 2GB limit? Serving static files directly is not an option in some cases (when the response is being generated on the fly, for instance). – Milos Mrdovic Dec 24 '17 at 22:13
  • Have you actually tried recent mod_wsgi versions. Not sure if there is a 2GB limit any more. The issues enforcing that may have been resolved. Note that Linux distros usually have ancient, obsolete and unsupported versions. Should always avoid distro packages unless you have a very good reason. – Graham Dumpleton Dec 25 '17 at 03:18

0 Answers0