Forums

No module named _ssl

I have been setting up a django app, that verify via email when someone sign up in my webpage, but when I click to send the email appears this error, I use python 2.7 and Django 1.10.5. I searched in the internet but the solutions that I found didn't work. I think the problem is python can't find the built-in module _ssl, but I don't know how to find it.

 2017-11-28 15:42:05,978: Error running WSGI application
 2017-11-28 15:42:05,991: ImportError: No module named _ssl
 2017-11-28 15:42:05,991:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/contrib/staticfiles   /handlers.py", line 63, in __call__
 2017-11-28 15:42:05,991:     return self.application(environ, start_response)
 2017-11-28 15:42:05,992:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in __call__
 2017-11-28 15:42:05,992:     response = self.get_response(request)
 2017-11-28 15:42:05,992:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response
 2017-11-28 15:42:05,992:     response = self._middleware_chain(request)
 2017-11-28 15:42:05,993:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
 2017-11-28 15:42:05,993:     response = response_for_exception(request, exc)
 2017-11-28 15:42:05,994:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 86, in response_for_exception
 2017-11-28 15:42:05,994:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
 2017-11-28 15:42:05,995:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 124, in handle_uncaught_exception
 2017-11-28 15:42:05,995:     extra={'status_code': 500, 'request': request},
 2017-11-28 15:42:05,995:   File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
 2017-11-28 15:42:05,995:     self._log(ERROR, msg, args, **kwargs)
 2017-11-28 15:42:05,996:   File "/usr/lib/python2.7/logging/__init__.py", line 1271, in _log
 2017-11-28 15:42:05,996:     self.handle(record)
 2017-11-28 15:42:05,996:   File "/usr/lib/python2.7/logging/__init__.py", line 1281, in handle
 2017-11-28 15:42:05,996:     self.callHandlers(record)
 2017-11-28 15:42:05,997:   File "/usr/lib/python2.7/logging/__init__.py", line 1321, in callHandlers
 2017-11-28 15:42:05,997:     hdlr.handle(record)
 2017-11-28 15:42:05,997:   File "/usr/lib/python2.7/logging/__init__.py", line 749, in handle
 2017-11-28 15:42:05,997:     self.emit(record)
 2017-11-28 15:42:05,998:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/utils/log.py", line 121, in emit
 2017-11-28 15:42:05,998:     self.send_mail(subject, message, fail_silently=True, html_message=html_message)
 2017-11-28 15:42:05,998:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/utils/log.py", line 124, in send_mail
 2017-11-28 15:42:05,998:     mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
 2017-11-28 15:42:05,999:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/utils/log.py", line 127, in connection
 2017-11-28 15:42:05,999:     return get_connection(backend=self.email_backend, fail_silently=True)
 2017-11-28 15:42:05,999:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 36, in get_connection
 2017-11-28 15:42:05,999:     klass = import_string(backend or settings.EMAIL_BACKEND)
 2017-11-28 15:42:06,000:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 20, in import_string
 2017-11-28 15:42:06,000:     module = import_module(module_path)
 2017-11-28 15:42:06,000:   File "/home/SimonCM/SAP/env/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 3, in <module>
 2017-11-28 15:42:06,000:     import ssl
 2017-11-28 15:42:06,001:   File "/usr/lib/python2.7/ssl.py", line 61, in <module>
 2017-11-28 15:42:06,001:     import _ssl             # if we can't import it, let the error propagatee

It looks like your site is running inside a virtualenv -- how did you create the env?

I created it with:

virtualenv env

that's some very strange behaviour for a virtualenv -- part of the traceback seems to have jumped out to the standard system-installed python libraries...

try creating a new virtualenv with a different name? or, just in case, using a different virtualenv creation tool? eg

mkvirtualenv --python=python2.7 myenv

(you can then just use the name "myenv" on the web tab and the system will auto-detect the virtualenv)...

Problem solved!!, creating a new virtualenv was the solution. I think when I run with the first virtualenv I forgot to change to use the python provided by the server and continue using the version of my local PC, thanks fo the quick replies and assistance :D

:)