Adding openssl support to Python (the right way)

Recently I have been doing some Python stuff on Linux. For the most part, I am either using Windows for my job and Mac probably for the entertainment stuff. But whenever I get to do something on Linux, may it be installing something or working on it, I find one thing every time. Its not straight forward.

So what I wanted was to install Python, run my Python script which does some webservice calls, and go for my lunch. One caveat, the service needs to be accessed using https. So I need ssl support in Python. I am like, this is something that needs to be there by default. But its not. Argh!!!! Some mortals like me posted queries http://stackoverflow.com/questions/979551/adding-ssl-support-to-python-2-6. So I asked my friends to ahead with their lunch, its going to take a while!

Enough of my sarcasm, to get to the point, follow these steps to add ssl support on a box running RHEL. My box has RHEL5.

Download Python source, I was installing 2.7.2, http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz

Extract it in a folder, say Python2.7.2. Do ./configure with any switches you need. In my case, I needed to add zlib support so, did this,

./configure –with-zlib=/usr/include

This creates a file called Setup and Setup.dist in Modules folder. To be safe, edit the Setup file. Locate the commented ssl section,

# Socket module helper for socket(2)
#_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
#_ssl _ssl.c \
#       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#       -L$(SSL)/lib -lssl –lcrypto


For those who have no clue what this file is, # means a commented line :). Uncomment few lines and change the SSL variable as below,



# Socket module helper for socket(2)
_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/ssl
_ssl _ssl.c \        
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \        
-L$(SSL)/lib -lssl -lcrypto


Save the file. Now do a make.
Now you might need to enter a root password. So do su – and then enter the root password. Once done, do make install. This should do it. At least it did for me and finally I had my lunch. Did you have your lunch yet!

Happy Programming!!!

Abhang Rane


No comments :

Post a Comment

Leave a Comment...