Compiling Python with SSL Support (Fedora 10)

Posted Wednesday, 03 March 2010 at 20:13 by Andrew Liu
Tagged: python | linux | fedora
Read more blogs...

 

I came across this recently, having always thought that this was part of Python.  When I installed a vanilla Fedora 10 installation, shock horror, I got this error in python!

 

> python
Python 2.6.1 (r261:67515, Feb  6 2009, 06:29:15)
[GCC 4.3.2 20081105 (Red Hat 4.3.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Python-2.6.1/lib/python2.6/ssl.py", line 60, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: No module named _ssl
>>> import httplib.HTTPSConnection
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named HTTPSConnection
>>>

No SSL? Unheard of! Quickly check to see if you have OpenSSL installed.

 

> yum list installed | grep ssl
openssl.i686                              0.9.8g-12.fc10               installed

 

So the first thing I did was install the development packages.  Normally they are required when you are compiling your own installation of python.

 

> yum install openssl-devel
Loaded plugins: refresh-packagekit
fedora                                                   | 2.8 kB     00:00
updates                                                  | 2.3 kB     00:00
updates/primary_db                                       | 2.5 MB     00:03
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package openssl-devel.i386 0:0.9.8g-12.fc10 set to be updated
--> Processing Dependency: krb5-devel for package: openssl-devel
--> Running transaction check
---> Package krb5-devel.i386 0:1.6.3-16.fc10 set to be updated
--> Processing Dependency: keyutils-libs-devel for package: krb5-devel
--> Processing Dependency: libselinux-devel for package: krb5-devel
--> Processing Dependency: e2fsprogs-devel for package: krb5-devel
--> Running transaction check
---> Package e2fsprogs-devel.i386 0:1.41.4-1.fc10 set to be updated
--> Processing Dependency: e2fsprogs-libs = 1.41.4-1.fc10 for package: e2fsprogs-devel
--> Processing Dependency: device-mapper-devel >= 1.02.02-3 for package: e2fsprogs-devel
---> Package libselinux-devel.i386 0:2.0.73-1.fc10 set to be updated
--> Processing Dependency: libsepol-devel >= 2.0.32-1 for package: libselinux-devel
---> Package keyutils-libs-devel.i386 0:1.2-3.fc9 set to be updated
--> Running transaction check
---> Package device-mapper-devel.i386 0:1.02.27-7.fc10 set to be updated
--> Processing Dependency: e2fsprogs-libs = 1.41.3-2.fc10 for package: e2fsprogs
---> Package libsepol-devel.i386 0:2.0.33-1.fc10 set to be updated
---> Package e2fsprogs-libs.i386 0:1.41.4-1.fc10 set to be updated
--> Running transaction check
---> Package e2fsprogs.i386 0:1.41.4-1.fc10 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                   Arch       Version               Repository     Size
================================================================================
Installing:
 openssl-devel             i386       0.9.8g-12.fc10        updates       1.9 M
Updating:
 e2fsprogs                 i386       1.41.4-1.fc10         updates       738 k
 e2fsprogs-libs            i386       1.41.4-1.fc10         updates       151 k
Installing for dependencies:
 device-mapper-devel       i386       1.02.27-7.fc10        updates        49 k
 e2fsprogs-devel           i386       1.41.4-1.fc10         updates       683 k
 keyutils-libs-devel       i386       1.2-3.fc9             fedora         27 k
 krb5-devel                i386       1.6.3-16.fc10         fedora        1.1 M
 libselinux-devel          i386       2.0.73-1.fc10         fedora        117 k
 libsepol-devel            i386       2.0.33-1.fc10         fedora         60 k

Transaction Summary
================================================================================
Install      7 Package(s)
Update       2 Package(s)
Remove       0 Package(s)

Total download size: 4.8 M
Is this ok [y/N]: y
Downloading Packages:
(1/9): keyutils-libs-devel-1.2-3.fc9.i386.rpm            |  27 kB     00:00
(2/9): device-mapper-devel-1.02.27-7.fc10.i386.rpm       |  49 kB     00:00
(3/9): libsepol-devel-2.0.33-1.fc10.i386.rpm             |  60 kB     00:00
(4/9): libselinux-devel-2.0.73-1.fc10.i386.rpm           | 117 kB     00:00
(5/9): e2fsprogs-libs-1.41.4-1.fc10.i386.rpm             | 151 kB     00:00
(6/9): e2fsprogs-devel-1.41.4-1.fc10.i386.rpm            | 683 kB     00:01
(7/9): e2fsprogs-1.41.4-1.fc10.i386.rpm                  | 738 kB     00:01
(8/9): krb5-devel-1.6.3-16.fc10.i386.rpm                 | 1.1 MB     00:01
(9/9): openssl-devel-0.9.8g-12.fc10.i386.rpm             | 1.9 MB     00:02
--------------------------------------------------------------------------------
Total                                           570 kB/s | 4.8 MB     00:08
============================== Entering rpm code ===============================
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : keyutils-libs-devel                                     1/11
  Installing     : device-mapper-devel                                     2/11
  Installing     : libsepol-devel                                          3/11
  Updating       : e2fsprogs-libs                                          4/11
  Installing     : e2fsprogs-devel                                         5/11
  Installing     : libselinux-devel                                        6/11
  Installing     : krb5-devel                                              7/11
  Updating       : e2fsprogs                                               8/11
  Installing     : openssl-devel                                           9/11
  Cleanup        : e2fsprogs-libs                                         10/11
  Cleanup        : e2fsprogs                                              11/11
=============================== Leaving rpm code ===============================

Installed:
  openssl-devel.i386 0:0.9.8g-12.fc10

Dependency Installed:
  device-mapper-devel.i386 0:1.02.27-7.fc10
  e2fsprogs-devel.i386 0:1.41.4-1.fc10
  keyutils-libs-devel.i386 0:1.2-3.fc9
  krb5-devel.i386 0:1.6.3-16.fc10
  libselinux-devel.i386 0:2.0.73-1.fc10
  libsepol-devel.i386 0:2.0.33-1.fc10

Updated:
  e2fsprogs.i386 0:1.41.4-1.fc10       e2fsprogs-libs.i386 0:1.41.4-1.fc10

Complete!

 

Jeepers, a lot for just installing one package!  But it serves it purpose.

 

> yum list installed | grep ssl
openssl.i686                              0.9.8g-12.fc10               installed
openssl-devel.i386                        0.9.8g-12.fc10               installed

 

Now I had to modify the file Modules/Setup.dist in the Python source (mine was located in /usr/local/src/Python-2.6.1).  Change the following lines (highlighted in red).

 

> vi Modules/Setup.dist

 

...

206 # CSV file helper
207 #_csv _csv.c
208
209 # Socket module helper for socket(2)
210 _socket socketmodule.c
211
212 # Socket module helper for SSL support; you must comment out the other
213 # socket line above, and possibly edit the SSL variable:
214 #SSL=/usr/local/ssl
215 _ssl _ssl.c \
216     -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
217     -L$(SSL)/lib -lssl -lcrypto

218
219 # The crypt module is now disabled by default because it breaks builds
220 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
221 #
222 # First, look at Setup.config; configure may have set this for you.
223
224 #crypt cryptmodule.c # -lcrypt  # crypt(3); needs -lcrypt on some systems

 

Unfortunately, I had to remake the python installation.  But this should be painless.  Remember, I like to point to the specific prefix location; you may not.  It should be much faster second time (or third time...) round.

 

> .configure --prefix=/usr/local/Python-2.6.1

> make

> make install

 

Check that python now has ssl.

 

> python
Python 2.6.1 (r261:67515, Feb 27 2009, 02:54:13)
[GCC 4.3.2 20081105 (Red Hat 4.3.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>

 

 

No more error!  Now we have SSL support in Python.

Thanks for the following posts from Grig Gheorghiu and Patrick Altman for their help.

 

 

Web News

The Dangers of HTML5: WebSockets and Stable Standards
New HTML5 technologies like WebSockets offer some amazing new opportunities for Web developers. But they also show how implementing unstable standards may cause more harm to a site than the benefits of the technology. What is the role of browsers and how should developers plan for when developing with HTML5?
2011-05-09T21:00:23-04:00

Internet Explorer 6: What Have We Learned?
IE6 shipped more than 10 years ago, but its non-standard implementation of the shifting standards of 2001 still haunts today's developers. As the Web shifts to HTML5, and new versions of IE, Firefox and Chrome debut, have we learned the lessons of IE6?
2011-05-09T20:50:33-04:00

Crank Up the Volume with HTML5 Music
With HTML5, music is making a comeback on the Web. Create amazing music site experiences where adding an audio file is as simple as inserting an image and users have more pause and play music outside a browser. The introduction of the tag eliminates the need for external music players, allowing for true integration of sound in your website.
2011-05-09T20:44:42-04:00

Dojo.behavior: Write Modularized HTML Document Event Handling
The dojo.behavior module provides a simple and lightweight mechanism for listening to HTML document events. Find out what makes dojo.behavior one of the best event handling mechanisms around.
2011-04-27T14:11:59-04:00

The Dojo Publish/Subscribe Event Mechanism
Learn how to use the Dojo Toolkit's versatile ContentPane widget to load dynamic content into your Web pages.
2011-04-25T07:04

Company Blog


Search Behaviour

Posted Tuesday, 19 October 2010 at 05:58 by Andrew Liu


As an SEO provider, you have one main goal. Get your client’s website to show up in search res...

Read more...



"sm bus" drivers missing in Device Manager

Posted Thursday, 18 March 2010 at 20:51 by Andrew Liu


When installing a new Windows XP installation, I seemingly always miss some drivers. One that troub...

Read more...



Link Building SEO Strategies

Posted Monday, 08 March 2010
Updated Tuesday, 09 March 2010 at 02:09 by Andrew Liu


Link building might be a necessary step for your search engine optimisation campaign, but very few p...

Read more...



Multiple Domains for SEO performance?

Posted Friday, 05 March 2010 at 23:13 by Andrew Liu


Online businesses and websites that cover a broad range of topics or one large topic are sometimes b...

Read more...



Tag Clouds - SEO or not?

Posted Thursday, 04 March 2010 at 04:34 by Andrew Liu


A tag cloud or word cloud is a visual depiction of tags or words related to a site, typically used t...

Read more...



Read more blogs...