Forums

OSError: Write Error

Getting lots of OSError: Write Error many times in a day in my error log. Looking at old forum threads it appears to be causable by 2 things - attempting to touch wsgi.py and messing that up, or cookies failing to be set in a browser. Anyone have any clue why any of these could be happening?

show us the code that is producing the error

Those normally happen when a browser disconnects from your site while it's trying to send back a response. All sites get a few of them from time to time, because people connect over unreliable networks (for example, mobile) and get disconnected, but if you're getting a lot it might be a sign of a problem.

The most likely cause is that one or more of the views on your site are slow to return a response -- then people will give up and click away to another page, or hit refresh, or do something else that will interrupt the connection. I'd suggest looking at the access log for the site -- each request you get has a line in there, and they all have a response-time in seconds at the end. A quick and easy way to find the requests that were interrupted is to search for " 499 " -- that's space, 4, 9, 9, space -- which will take you to lines with a 499 status code. 499 is a synthetic status code that nginx puts into the access logs when the browser disconnects.

Once you've found which views are running slowly enough that people are interrupting them, you can take a look at your code to try to work out why they're running slowly.

This seems sort of right. Just today, I've gotten this many errors:

2019-10-08 11:17:44,606: OSError: write error
2019-10-08 11:17:44,608: OSError: write error
2019-10-08 11:17:44,622: OSError: write error
2019-10-08 12:21:50,935: OSError: write error
2019-10-08 14:46:05,534: OSError: write error
2019-10-08 14:46:05,535: OSError: write error
2019-10-08 16:05:28,771: OSError: write error
2019-10-08 16:16:03,225: OSError: write error
2019-10-08 16:16:18,039: OSError: write error
2019-10-08 16:47:11,276: OSError: write error
2019-10-08 16:47:11,301: OSError: write error
2019-10-08 17:41:29,032: OSError: write error
2019-10-08 17:45:55,173: OSError: write error
2019-10-08 19:06:37,768: OSError: write error
2019-10-08 19:06:37,783: OSError: write error
2019-10-08 21:02:06,188: OSError: write error
2019-10-09 00:26:46,175: OSError: write error
2019-10-09 00:27:46,375: OSError: write error
2019-10-09 01:19:09,919: OSError: write error
2019-10-09 01:57:23,046: OSError: write error
2019-10-09 01:57:23,106: OSError: write error
2019-10-09 03:16:00,727: OSError: write error
2019-10-09 04:22:51,426: OSError: write error
2019-10-09 11:02:28,651: OSError: write error
2019-10-09 12:01:18,268: OSError: write error
2019-10-09 12:24:24,783: OSError: write error
2019-10-09 12:24:24,816: OSError: write error
2019-10-09 15:30:31,227: OSError: write error
2019-10-09 15:30:31,226: OSError: write error
2019-10-09 15:33:22,601: OSError: write error
2019-10-09 16:42:37,676: OSError: write error
2019-10-09 16:44:19,278: OSError: write error
2019-10-09 16:44:19,619: OSError: write error
2019-10-09 16:47:06,667: OSError: write error
2019-10-09 16:48:54,776: OSError: write error
2019-10-09 16:48:54,789: OSError: write error
2019-10-09 16:49:27,862: OSError: write error
2019-10-09 16:56:18,781: OSError: write error
2019-10-09 16:57:16,560: OSError: write error

I'm worried that I can't find what view specifically is causing the redirects - in addition, some are literally just 0.5 seconds response time - does this mean the website loaded in 0.5 seconds, or that they redirected away by going somewhere else after just 0.5 seconds. If it's the former, there's not much I can do about this right - they're just leaving before my site's loaded, right?

why do you think there is a redirect in your code? this should be user side behavior, where they click to go to a different page while your page is still loading. it could be going to a different page on your site. but as Giles said, check the 499 status codes in your access log to see what pages they are leaving from. if you don't see a pattern- could it just be that you have high traffic and not enough webworkers to serve all your web requests quickly enough?

there are redirects - i redirect from a link whcih sets cookies to my index page. the 499 status codes just say they're leaving as they load different static files - some the css, some the js, they're leaving as those are loading. that would probably indicate that they just left while the website was loading right?

as for the high traffic - my google analytics says i have around 2k unique users, but the pythonanywhere stats say ive had 65k nonunique hits in the past 2 months - is there any more info on what the hits traffic means?

if you mean that there are external links that link/direct to your index page, then that shouldn't matter her.

yes the 499s mean that your users are leaving before your front page has finished loading. You should setup static files mapping so that your core webservers don't need to serve the static files and just needs to serve the base front page.

the reason for the hits is probably because each page might have multiple hits to multiple static assets. another reason to put them as a static file mapping.

if you are still seeing very slow speeds after fixing that, then you should consider putting a cdn in front of pythonanywhere, or adding more webworkers.

thanks for the advice! i'll look into all of this