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!!!

Using Fiddler on Linux

If you are a web programmer, I am sure you would have come across a juncture where you needed some kind of tool that kept a steady eye on the network traffic. On Windows, a sexy tool that does this is Fiddler. You are using Windows, doing your programming, observing what requests flow in and out, all is well. Your boss asks you to write some kind of wise script that would some magic on the network like calling some webservice, ftp etc. You say, ‘huh… piece of cake’. Oh ya, the boss says, just one thing, this script runs on Linux.

Doh!!!!

Not really a “Doh” moment. Fiddler has a nice feature of remote connections. What you do is set the proxy on your Linux box, the proxy would have the ip address/computer name of a windows machine that is running Fiddler. That’s it, all the network traffic is routed to the Fiddler instance running on your beloved Windows machine. For those who understand in terms of some screenshots, here is the link from Fiddler website, http://www.fiddler2.com/fiddler/help/hookup.asp#Q-NonWindows

In my case, I had to put the IP address of my Windows machine and the port 8888 on which Fiddler was running. Computer names might not be searchable on all networks.

Happy Programming!!!