[issue11725] httplib and urllib2 failed ssl connection httplib.BadStatusLine

Isaac Salsberg report at bugs.python.org
Fri Sep 23 21:13:56 CEST 2011


Isaac Salsberg <isalsberg at users.sourceforge.net> added the comment:

The output for the command: 

   $ openssl s_client -connect www.finratrace.org:443

was the same on MAC OS X 10.6 and on Red hat 5 (https works fine under linux).

Nevertheless, Ned Deily is right: the bug is on the openssl libs supplied with OS X 10.6 

To solve this issue, I compiled and install OpenSSL 1.0.0d and then link python against this library.

This is the full recipe, step by step:

1. Install openssl. 
   Download the source tar for openssl. I used version openssl-1.0.0d.
   To build 64-bit library, then you have to invoke 
   './Configure darwin64-x86_64-cc' *manually*. Also, to make ssl work in python,
   the openssl libraries must be 'shared libraries'. 
   

   First, Expand the tar file into a temporary directory, I am using /tmp:
   
   $ cd /tmp
   
   $ tar xvzf openssl-1.0.0d.tar.gz
   
   $ cd openssl-1.0.0d
   

   To Build openssl as 64 bits shared libraries and install it:
   
   $ ./Configure darwin64-x86_64-cc shared
   
   $ make 
   
   $ make test # this step is optional
   
   $ sudo make install
   
   
   This will install openssl in the default directory: /usr/local/ssl
   
2. Compile and install python. 
   Download the source tar file. I used version Python 2.7.2
   
   a) Expand the tar file (again into a temporary directory)
   
   b) then go into the Modules folder
   
   c) vi the Setup.dist file, looking for the SSL string (if your are not familiar 
      with vi, you can use any text editor), then uncomment the lines BELLOW the 
      message:
      
               "# Socket module helper for SSL support ..."
               
      Your file must look as follows:
   
   
# 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
 
   

   d) Then using python defaults (installing under /usr/local) execute:
   
   $   ./configure 

   $ make

   $ make test # optional

   $ sudo make install
   

3. To test if python now has ssl support, start python and execute
   these commands (be sure you invoke the new python under /usr/local/bin):

imac:~ isaac$ /usr/local/bin/python
Python 2.7.2 (default, Jun 30 2011, 16:00:06) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import httplib
>>> hasattr(httplib, 'HTTPS')
True
>>> # MUST be  True, otherwise has NO ssl support
... 
>>> import socket
>>> hasattr(socket,'ssl')
True
>>> # MUST be  True, otherwise has NO ssl support
... 
>>> import _ssl
>>> # should NOT give any error when importing
... 
>>> 


That's all, now you have ssl support with python under MAC OS X 10.6

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11725>
_______________________________________


More information about the Python-bugs-list mailing list