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

Google's head of Pixel smartphone division leaves after six months
After David Foster's departure, Google still plans to release at least two new Pixel smartphones this fall, according to rumors.
--- 30 Apr 2017 08:47 AM

Elon Musk releases teaser image of Tesla semi truck
Tesla's 'next level' cargo truck will be revealed in September and will be capable of making long hauls, according to Musk during a TED talk.
--- 30 Apr 2017 07:47 AM

The death of the smartphone is further away than you think. And there is no 'Next Big Thing'
The smartphone represents the latest major platform shift, and it may also be the last one. We will still need the smartphone's functionality, and no wearable device looks like offering a single viable replacement. Pacific Crest's Ben Wilson suggests looking for a range of AI-based devices instead
--- 30 Apr 2017 07:22 AM

Today's customer experience mandate: Avoid '50 first dates'
These days, digital channel proliferation is making it more complex than ever to connect with and satisfy customers, whose own expectations of service are growing rapidly. Maintaining a coherent digital experience appears to be an essential element of the solution.
--- 30 Apr 2017 05:26 AM

SpeedCast: Satellite business growing off global military spending increase
SpeedCast is seeing growing government uptake of its satellite communications services thanks to increasing military spending across the US, the UK, Europe, and Australia.
--- 29 Apr 2017 02:00 PM

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 clients website to show up in search results fo...

Read more...



sm bus drivers missing in Device Manager

Posted Sunday, 18 April 2010
Updated Sunday, 24 February 2013 at 06:39 by Andrew Liu


When installing a new Windows XPinstallation, I seemingly always miss some drivers. One that trouble...

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



Mozilla Thunderbird and Gmail IMAP Attachments Bug

Posted Wednesday, 03 March 2010 at 20:15 by Andrew Liu


I've been using Gmail since its early inception, and Iwas one of the first to utilise Gmail's IMAPfe...

Read more...



Read more blogs...