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.

 

 

Except: (1, 2)
Traceback (most recent call last): File "/apps/case-users/webtop/case/case/case/model/content.py", line 577, in print_text text = template.render_unicode(**globs) File "/apps/case-users/webtop/lib/python2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/template.py", line 198, in render_unicode as_unicode=True) File "/apps/case-users/webtop/lib/python2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/runtime.py", line 403, in _render _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data)) File "/apps/case-users/webtop/lib/python2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/runtime.py", line 434, in _render_context _exec_template(inherit, lclcontext, args=args, kwargs=kwargs) File "/apps/case-users/webtop/lib/python2.6/site-packages/Mako-0.3.2-py2.6.egg/mako/runtime.py", line 457, in _exec_template callable_(context, *args, **kwargs) File "memory:0x2aaab1d0c910", line 67, in render_body File "/apps/case-users/webtop/case/case/xbits/helpers.py", line 421, in quote return urllib.quote(s) File "/usr/local/Python-2.6.5/lib/python2.6/urllib.py", line 1222, in quote res = map(safe_map.__getitem__, s) KeyError: u'\u2019'