MemoryError in python with chunked uploading

I am writing server side for chunked uploading files. So sometimes i got MemoryError and i can`t understand what i am doing wrong. Here my python code(with framework pyramid):

@view_config(route_name='fileupload',renderer='../upload.mako')
def upload_file(request):
    session = request.session
    if 'authorized' in session and session['authorized'] is False:
        return HTTPForbidden()
    try:
        filename = request.params.get('filename')
        print request.params.get('chunkindex')
        datatmp = request.params.get('data')
        data64 = datatmp[13:]
        data = base64.b64decode(data64)
        f = open('/home/somedirectory/' + filename , 'ab')
        f.write(data)
        f.close()
    except Exception as e:
        print e
    return {}

Error traceback:

2015-07-24 17:57:36,630 ERROR [waitress][Dummy-5 340] Exception when serving /upload
Traceback (most recent call last):
  File "/home/myusername/project25/local/lib/python2.7/site- packages/waitress-0.8.9-py2.7.egg/waitress/channel.py", line 337, in   service
    task.service()
  File "/home/myusername/project25/local/lib/python2.7/site-packages/waitress-0.8.9-py2.7.egg/waitress/task.py", line 173, in service
self.execute()
  File "/home/myusername/project25/local/lib/python2.7/site-packages/waitress-0.8.9-py2.7.egg/waitress/task.py", line 392, in execute
app_iter = self.channel.server.application(env, start_response)
  File "/home/myusername/project25/local/lib/python2.7/site-packages/pyramid-1.5.6-py2.7.egg/pyramid/router.py", line 242, in __call__
response = self.invoke_subrequest(request, use_tweens=True)
  File "/home/myusername/project25/local/lib/python2.7/site-packages/pyramid-1.5.6-py2.7.egg/pyramid/router.py", line 217, in invoke_subrequest
response = handle_request(request)
  File "/home/myusername/project25/local/lib/python2.7/site-packages/pyramid_debugtoolbar-2.3-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 168, in toolbar_tween
toolbar = DebugToolbar(request, panel_classes, global_panel_classes)
  File "/home/myusername/project25/local/lib/python2.7/site-packages/pyramid_debugtoolbar-2.3-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 49, in __init__
panel_inst = panel_class(request)
  File "/home/myusername/project25/local/lib/python2.7/site-packages/pyramid_debugtoolbar-2.3-py2.7.egg/pyramid_debugtoolbar/panels/request_vars.py", line 30, in __init__
for k in request.POST],
  File "/usr/lib/python2.7/pprint.py", line 67, in saferepr
return _safe_repr(object, {}, None, 0)[0]
  File "/usr/lib/python2.7/pprint.py", line 323, in _safe_repr
rep = repr(object)
MemoryError 

Pyramid Debugtoolbar is raising this exception while trying to render the variables in your POST request.

You have this enabled in development environments, disable it running your application with your production.ini. Evaluate if the behaviour is different.

BTW: run the pyramid tutorial on authentication to protect your view to authenticated users, do not swallow exceptions this way and use logging statement instead of printing. Any Pyramid docs/tuts will apply these techniques.

链接地址: http://www.djcxy.com/p/96722.html

上一篇: 在收到第一个字节后停止superagent(仅获取重定向url)

下一篇: 在分块上传的python中的MemoryError