lundi 27 juillet 2015

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/http://ift.tt/1HWaSn2", line 337, in   service
    task.service()
  File "/home/myusername/project25/local/lib/python2.7/site-packages/http://ift.tt/1ceJQxk", line 173, in service
self.execute()
  File "/home/myusername/project25/local/lib/python2.7/site-packages/http://ift.tt/1ceJQxk", line 392, in execute
app_iter = self.channel.server.application(env, start_response)
  File "/home/myusername/project25/local/lib/python2.7/site-packages/http://ift.tt/1LMY2g1", line 242, in __call__
response = self.invoke_subrequest(request, use_tweens=True)
  File "/home/myusername/project25/local/lib/python2.7/site-packages/http://ift.tt/1LMY2g1", line 217, in invoke_subrequest
response = handle_request(request)
  File "/home/myusername/project25/local/lib/python2.7/site-packages/pyramid_debugtoolbar-http://ift.tt/1wFY0Re", 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-http://ift.tt/1wFY0Re", line 49, in __init__
panel_inst = panel_class(request)
  File "/home/myusername/project25/local/lib/python2.7/site-packages/pyramid_debugtoolbar-http://ift.tt/1OKnwcy", 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 




Aucun commentaire:

Enregistrer un commentaire