SSL support in Python doesn't always work out the box, especially when using
virtualenv.
You'll know you have a problem when you get an error similar to the following:
AttributeError: 'module' object has no attribute 'ssl'
However, after completing the above you will find that your system python passes the following quick test:
$ python
>>> import socket
>>> hasattr(socket, "ssl")
True
But your virtualenv:
/path/to/your/virtualenv/source bin/activate
Fails the same test:
$ python
>>> import socket
>>> hasattr(socket, "ssl")
False
It seems that virtualenv has problems picking up ssl settings, especially, in my experience, when openssl is installed after virtualenv. Creating fresh virtual environments has no effect.
To get round the problem, try the following:
Via your system python:
$ python
>>> import _ssl
>>> _ssl.__file__
You should get a path similar to (Do not modify anything in this directory):
/usr/local/lib/python2.5/lib-dynload/_ssl.so
Copy or symlink that to file in your virtualenv python site-packages folder:
cp /usr/local/lib/python2.5/lib-dynload/_ssl.so /path/to/your/virtualenv/lib/python2.5/site-packages/_ssl.so
And it should all work fine now. Test it in your virtualenv via the same command from earlier:
/var/odbody/uat/odbody-uat/source bin/activate
>>> import socket
>>> hasattr(socket, "ssl")
True
(Many thanks to
Marius Gedminas in #zope3-dev for his help with this problem)