Getting SSL Support in Python 2.5.1
If you find yourself on a linux box needing ssl support in python (to use a client in things like httplib.HTTPSConnection or imaplib.IMAP4_SSL), then let me save you a couple of hours of hunting around the web (of course if you have found this then that means you've done some level hunting already!).
You'll know if you need ssl support compiled into your python installation if you get the following exception message:
AttributeError: 'module' object has no attribute 'ssl'
In order to make that go away so you can continue happily slinging python code, you'll need to first make sure you have OpenSSL installed. By default it is installed from source at:
/usr/local/ssl
If that directory doesn't exist, then grab the source package.
Do the standard:
tar zxf openssl-0.9.8g.tar.gz cd openssl-0.9.8g ./config make make install
Then grab the python sources for 2.5.1 and:
tar zxf Python-2.5.1.tgz cd Python-2.5.1
Then you need to edit the Modules/Setup.dist:
204:# Socket module helper for SSL support; you must comment out the other 205:# socket line above, and possibly edit the SSL variable: 206:SSL=/usr/local/ssl 207:_ssl _ssl.c 208: -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl 209: -L$(SSL)/lib -lssl -lcrypto
If you installed OpenSSL in the default locations you can just uncomment lines 206-209, then:
./configure make make install
Then verify your installation with:
python /usr/local/lib/python2.5/test/test_socket_ssl.py test_rude_shutdown ... test_basic ... test_timeout ...
Commentary
After searching long and hard, this is exactly what the problem was for ssl support in Python. This works for 2.4 as well. Thanks for putting it up!
Thanks for this! I'd like to add something here for other users (since yours was a page I found after much hunting too and there's no point having another page):
Your instructions won't work if you use Linux on AMD64. There will be an error message that only shows when you try to do the test:
/usr/local/ssl/lib/libssl.a: relocation RX8664_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
A minor change that I've found after experimentation is to compile openssl with "enable-shared" as a parameter. i.e.
tar zxf openssl-0.9.8g.tar.gz cd openssl-0.9.8g ./config enable-shared make make install
DON'T, however, do the equivalent ./configure --enable-shared for Python.
Thanks dude. Worked like a charm. I owe you a beer!
Thanks a lot for this! I actually had to copy Setup.dist to Setup in order for it to find ssl for some reason...