处理WSGI脚本时发生异常 - IOError:无法写入数据

时间:2013-05-21 12:48:14

标签: python django mongodb django-uploads

我正在尝试在服务器端保存图像。我接收它为base64字符串,所以我先解码它然后将其保存在数据库中。但是这次失败了,所以我检查了服务器错误日志,我发现了以下 error.log中

    [Tue May 21 14:26:38 2013] [error] [client 41.236.182.133] mod_wsgi (pid=4952): Exception occurred processing WSGI script '/root/AR_BROWSER/example/wsgi.py'.
[Tue May 21 14:26:38 2013] [error] [client 41.236.182.133] IOError: failed to write data

我检查了wsgi.py

import os
import sys

path = '/root/AR_BROWSER/example'

sys.path.append('/root/AR_BROWSER/example')
sys.path.append('/root/AR_BROWSER')
sys.path.append('/root/AR_BROWSER/example/app')

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

但我找不到错误。知道这个问题的原因是什么?! 负责保存图像的代码

 @csrf_exempt    
    def create_app(request):
        appName = request.POST['name']
        user = request.POST['userID']
        c = request.POST['category']
        i = request.POST['image']
        imgdata = base64.b64decode(i)
        t = datetime.now()
        filename = t.strftime('test.jpg')  
        with open(filename, 'w') as f:
            f.write(imgdata)
            f.close()
        u=App_User.objects.get(id=user)
        apps = App.objects.create(name = appName, category=c, user_id = u.id, app_logo=File(filename))
        apps.save()

        return HttpResponse("You created %s." % apps.name)

1 个答案:

答案 0 :(得分:7)

来自mod_wsgi但没有回溯的消息通常意味着HTTP客户端在mod_wsgi将所有响应数据写回之前关闭了连接。