Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError: failed to write data #233

Closed
mayurpande opened this issue Oct 31, 2017 · 15 comments
Closed

OSError: failed to write data #233

mayurpande opened this issue Oct 31, 2017 · 15 comments

Comments

@mayurpande
Copy link

mayurpande commented Oct 31, 2017

I keep getting an OSError: failed to write data on my site. It seems my mysql data is not updating and deleting as it should be. But I cannot work out if this is to do with wsgi or the server. I have 3.5gb of RAM and it is hardly using 1gb. Here is my error log;




Am I missing something?

@GrahamDumpleton
Copy link
Owner

You will see that message when the HTTP client disconnects before all response data has been sent. It can occur normally if network connection dies (high chance for mobile users) or user navigates away from page before response comes.

@GrahamDumpleton
Copy link
Owner

GrahamDumpleton commented Feb 1, 2018

Can you upgrade mod_wsgi to latest version as the version you are using is quite old?

As I said this is normal. There were changes in more recent mod_wsgi version to try and not be so noisey with the messages in certain cases.

Also, are you using embedded mode or daemon mode of mod_wsgi?

@mayurpande
Copy link
Author

I just installed mod_wsgi in my virtual environment and it says I installed version 4.5.24, but still unsure about the libapache2-mod-wsgi-py3

@GrahamDumpleton
Copy link
Owner

Do not use any system package for mod_wsgi, especially on Debian/Ubuntu based systems. They are usually hopelessly out of date and unsupported. Remove any system package for mod_wsgi and install using pip and then configure Apache to load the module for the Python installation/virtual environment as explained in:

@mayurpande
Copy link
Author

Ok I just done that in my virtual env for mod_wsgi as I am using flask do I need to install libapache2-mod-wsgi-py3 in my virtual env as well?

@GrahamDumpleton
Copy link
Owner

Do not apt-get install any mod_wsgi package. So uninstall libapache2-mod-wsgi-py2 and libapache2-mod-wsgi-py3 from your system and then configure Apache by creating your own wsgi.load file in mods-available directory of Apache which contains the output of running:

mod_wsgi-express module-config

Then use the Apache command to enable the wsgi module.

a2enmod wsgi

@GrahamDumpleton
Copy link
Owner

I didn't say to put:

mod_wsgi-express module-config

in the wsgi.load file. I said to put the output from running it.

This is explained in section 'Connecting into Apache installation' of:

which I linked to earlier.

Read that again to get an explanation.

@mayurpande
Copy link
Author

I did read the docs, but got an error straight after pip install mod_wsgi it says run the script;

mod_wsgi-express start-server

I got the error mod_wsgi-express: command not found so it seems to not have installed properly, I installed both on pip and pip3

@GrahamDumpleton
Copy link
Owner

Do you have the virtual environment activated?

What do you get for running which pip?

@mayurpande
Copy link
Author

Yes virtual env is active.

The output of which pip : /var/www/html/Webscraper/Webscraper/my_env/bin/pip

@GrahamDumpleton
Copy link
Owner

What do you get from running:

pip freeze

and:

ls -als /var/www/html/Webscraper/Webscraper/my_env/bin

Also run:

python

and in the interpreter do:

import mod_wsgi
print(mod_wsgi.__file__)

What is output?

@GrahamDumpleton
Copy link
Owner

Run:

pip uninstall mod_wsgi

Keep running that until it says nothing to remove.

Then run:

pip install --no-cache-dir mod_wsgi

What is the output?

Do you have the apache2-dev system package installed?

@mayurpande
Copy link
Author

pip install --no-cache-dir mod_wsgi this line installed successfully

@GrahamDumpleton
Copy link
Owner

No.

Are you using daemon mode of mod_wsgi as is recommended? And delegating each separate WSGI application to a different daemon process group?

If you are, replace the WSGIPythonHome directive with:

WSGIRestrictEmbedded On

Then set python-home option on each WSGIDaemonProcess directives of the respective daemon process groups you created for each separate application.

If you are aren't using daemon mode, you should.

Also look at:

for how to set up virtual environments when using daemon mode.

Post the actual configs you are using when have something so I don't have to guess.

@GrahamDumpleton
Copy link
Owner

GrahamDumpleton commented Feb 5, 2018

Are you checking the Apache error logs and system startup logs for Apache at all? Apache wouldn't even have started with the configuration you use but the logs should have told you why.

For:

<VirtualHost *:80>
        ServerName site.com
        ServerAdmin admin@site.com

        WSGIDaemonProcess  site.com python-home=/var/www/html/Validation/Validation/vs/lib/site-packages/
        WSGIProcessGroup  site.com
        WSGIRestrictEmbedded On

        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptAlias / /var/www/html/Validation/validation.wsgi

        <Directory /var/www/html/Validation/Validation/>
                Require all granted
        </Directory>

</VirtualHost>

The:

WSGIRestrictEmbedded On

can't be inside of the VirtualHost. I said to replace the WSGIPythonHome in the wsgi.load file with that. You also didn't show me what you were using in wsgi.load even though I asked for you to provide the various configs so don't have to guess.

Also:

WSGIDaemonProcess  site.com python-home=/var/www/html/Validation/Validation/vs/lib/site-packages/

should be:

WSGIDaemonProcess  site.com python-home=/var/www/html/Validation/Validation/vs/lib/site-packages/

The python-home should refer to the root of the Python virtual environment, ie., what sys.prefix in Python is set to. It should not be pointing at the site-packages directory. The doc on setting up mod_wsgi with virtual environment explains that.

So try again, and make sure you are checking Apache error logs and system startup logs for Apache if Apache is not restarting. Include the details here of any errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants