Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception occurred processing WSGI script - IOError: failed to write data

I'm trying to save an image at the server side.I recieve it as base64 string so I decode it first and then save it in the database.However this failed, so I checked the server error log and I found the following 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

I checked 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()

But i can't find something wrong. Any idea what could be the cause of this issue?! the code responsible for saving the image

 @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)
like image 712
omarsafwany Avatar asked May 21 '13 12:05

omarsafwany


1 Answers

That message from mod_wsgi with no traceback generally means that the HTTP client closed the connection before all response data could be written back to it by mod_wsgi.

like image 127
Graham Dumpleton Avatar answered Nov 08 '22 01:11

Graham Dumpleton