Forums

ImportError: No module named 'sslify'

I have got a django web app. Everything is working fine. Now I try to force https (ssl). I followed the instructions here:

https://www.pythonanywhere.com/wiki/ForcingHTTPS

I set Debug = False and installed sslify in my root directory.

After adding silly to middleware class I get this error: ImportError: No module named 'sslify'

What do I miss?

Thanks!

Does this help? https://www.pythonanywhere.com/wiki/DebuggingImportError

Ok now I see that there is no sslify in sys.path - how can I add this permanently? I tried

import sys

sys.path.append("/home/vendair/.local/lib/python2.7/site-packages/sslify")

in the wsgi.py, but I still get the error...

I think I found a workaround.

I downloaded the sslify-django package from github and added the middleware.py to my project folder. In settings I changed "sslify.middleware.SSLifyMiddleware" to "myapp.middleware.SSLifyMiddleware" in the Middleware_Classes.

Now it is working fine, but I am not really sure if this causes some other problems. But we will see...

The best way to install sslify is to use pip with the --user flag:

pip install --user django-sslify

That will put it into the appropriate place in .local and update sys.path so that you don't have to.

I tried

pip install --user django-sslify

first.

The files had been installed to .local/lib/python2.7/site-packages/sslify/ But we I printed out the sys.path as mentioned in the wiki it does not appear.

That's strange. Was that in a new console, or a web app that you had reloaded? Or was it in one that had been running for a while?

New bash console.

/home/vendair/.local/lib/python2.7/site-packages/sslify should not be on sys.path, but check that /home/vendair/.local/lib/python2.7/site-packages/ is

Yes,

/home/vendair/.local/lib/python2.7/site-packages/

is in sys.path. But why I'm getting the import error?

Then the most likely cause is that you've installed sslify for the wrong version of Python. What version of python is your web app? Use the appropriate pip to install it (i.e. pip3.3 for Python 3.3 or pip3.4 for 3.4) pip without a version specified is for Python 2.7.

Pah! That is it! Now it is working! Thank you!

Thanks for confirming :-)