Forums

OSError: write error

I have a flask app that writes to a .txt file to keep track of blacklisted IPs. It works most of the time, but occasionally I get an error, "OSError: write error"

My confusion here is, the exact same code never has this issue on replit or when hosted locally, the issue seems to be exclusive to pythonanywhere. For now I've resolved it by adding error handling and having it retry if it fails, works fine, but why am I getting write errors with pythonanywhere in the first place?

(Extra note: I always close my files at the end of each function and I tested to see if it was crossover, but even when I que writing to the file to ensure there is no possible crossover, the error still occurs. Also, I know I could also switch to using SQL to store the IPs but I want to figure out what's going on here regardless.)

Do the errors look like the ones mentioned in this help page? If so, they may be a result of your site running slowly -- check out the page for more information.

Thanks for the speedy reply! Though I have seen "broken pipe" errors before, this specific situation I'm referring to seems completely isolated. Like this: "2022-04-03 02:35:49,428: OSError: write error" with nothing related to the error above or below it, just that one line. Repeats every once in a while, but I've only had it happen twice after posting that, so it's not as frequent as before. Which... I upgraded my CPU seconds allowance since that post so you're probably still right actually, I think I was in the tarpit at the time.

I think it could still be the site running slowly -- or even just super-impatient people not waiting more than a second for a page, or people viewing the site from bad internet connections (where they might make a request, and then disconnect milliseconds later as their cellphone drops out of coverage).

TBH if you're just seeing very rare errors like that, but aren't seeing any complaints from people using your site, you can probably just treat it as "bad weather" -- random noise in the logs due to the unreliability of the internet.

Oh, that's probably it actually!!! One of my pages takes a couple seconds to load sending information, maybe users are just being impatient and slapping refresh mid-write. That would make a lot of sense come to think of it, especially since i haven't gotten any complaints about it. Thanks for the help, you rock!

That would make sense, yes -- glad we could help!