43

What could be causing this error:

$ sudo tail -n 100 /var/log/apache2/error.log'

[Wed Dec 29 15:20:03 2010] [error] [client 220.181.108.181] mod_wsgi (pid=20343): Exception occurred processing WSGI script '/home/username/public_html/idm.wsgi'.  
[Wed Dec 29 15:20:03 2010] [error] [client 220.181.108.181] IOError: failed to write data  

Here is the WSGI script:

$ cat public_html/idm.wsgi 
import os
import sys

sys.path.append('/home/username/public_html/IDM_app/')

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

import django.core.handlers.wsgi

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

Why would Django not be able to write data?

I'm running Django 1.2.4

BryanWheelock
  • 12,146
  • 18
  • 64
  • 109

4 Answers4

31

That error, without any sort of Python traceback, may be a variation on issue described in:

http://code.google.com/p/modwsgi/issues/detail?id=29&can=1

That is, occurs when HTTP client connection is lost before the full response could be written back by the web server. It can manifest as 'client closed connection', 'failed to write data' or 'failed to flush data' IOError in Apache error log only. Ie., not seen by WSGI applicaton because the writing of data is occurring after WSGI application has returned and so can't throw exception back to the application to do anything with.

The question is whether you get an error message from Django if you configure errors to be sent to you in email. If you do, then instead is something happening in Django.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • But how to solve it? In my application it seems to be related to send_mail (which takes a long time)... – gabn88 Jul 11 '15 at 11:16
  • 1
    There is no point adding a vague question with no specific information about your case to an existing followup to someone else's question. Your situation could be completely different. Create a new question explaining in detail your problem. – Graham Dumpleton Jul 11 '15 at 21:17
  • I'm sorry, but I got the same error, and I configured Django to send email, but got no mail. In my case the problem was that I changed my smtp mailbox password without changing it in Django. Might help someone in the future who is searching for the same problem like I did... No means to do anybody harm! – gabn88 Jul 12 '15 at 06:54
6

I have the same problem in an application that uses a lot of AJAX calls (mod_wsgi 3.3). Is there any known solution for this? I thought about just ignoring the exception, but that is normally not a very good idea.

UPDATE

Actually, this can be due to several things, but the most probable cause is that you are using the write callback instead of yielding your output.

I believe this will help:

http://groups.google.com/group/modwsgi/browse_thread/thread/c9cc1307bc10cfff

ubik
  • 4,440
  • 2
  • 23
  • 29
  • 1
    Will happen with either write or yield, makes no difference. Django doesn't use write only yield. If write were being used, the error would propagate back into the WSGI application and the application would likely catch it and be converted to a 500 with it not being logged. For the yield, it is mod_wsgi writing the data and no way to propagate error back to application, so mod_wsgi logs error with no traceback as not in context of application. – Graham Dumpleton May 23 '13 at 10:28
0

I've found the same problem with my python web app in Digital ocean and after checking the log file seriously I've discovered that It was a problem with my Database mysql ! The problem was due to the fact that I was running out storage (RAM) So check those question and solve the problem!

`For Mysql

And this

Hope It will help

Community
  • 1
  • 1
Espoir Murhabazi
  • 5,973
  • 5
  • 42
  • 73
-5

I'm wagering it is a permissions issue. True making the target directory/file universally writable. Then make the file owned by your www-data group (or whatever your apache user is), make it group writable, and make sure nothing in that folder is sensitive because this could be a security problem.

chriscauley
  • 19,015
  • 9
  • 33
  • 33