在分块上传的python中的MemoryError

我正在编写分块上传文件的服务器端。 所以有时我得到了MemoryError,我不明白我做错了什么。 这里我的Python代码(与框架金字塔):

@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 {}

错误追溯:

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在尝试呈现POST请求中的变量时引发此异常。

您可以在开发环境中启用此功能,并禁用它在production.ini中运行您的应用程序。 评估行为是否不同。

BTW:在身份验证上运行金字塔教程,以保护您的视图为经过身份验证的用户,不要以这种方式吞服异常,并使用日志语句而不是打印。 任何金字塔文件/图将应用这些技术。

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

上一篇: MemoryError in python with chunked uploading

下一篇: NSURLConnection vs NSStream for rapid server communication