Tuesday, February 6, 2018

Can't connect to HTTPS URL because the SSL module is not available.


Try to run python but encountered this error:

[root@nbu773srv1 tmp]# python3 get-pip.py 
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Requirement already up-to-date: pip in /usr/local/lib/python3.7/site-packages
Collecting wheel
  Could not fetch URL https://pypi.python.org/simple/wheel/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement wheel (from versions: )
No matching distribution found for wheel

ENV: Python 3.7 + CentOS 7.4

Resolution:

1. Please confirm if you can find openssl & openssl-devel rpm from OS.
# rpm -qa |grep openssl
openssl-libs-1.0.2k-8.el7.x86_64
openssl-1.0.2k-8.el7.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64

2. Install openssl-devel using yum
# yum install openssl-devel.x86_64 

Then check the result:
# rpm -qa |grep openssl
openssl-libs-1.0.2k-8.el7.x86_64
openssl-1.0.2k-8.el7.x86_64
openssl-devel-1.0.2k-8.el7.x86_64
xmlsec1-openssl-1.2.20-7.el7_4.x86_64

3. Modify the source installation file
vi /Modules/Setup
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.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

4. Finally, you need to compile the python again.
# make & make install

5. Now, you can use ssl in python 3.
[root@nbu773srv1 tmp]# python3
Python 3.7.0a4 (default, Feb  6 2018, 13:44:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl

2 comments:

Tommy said...

some interesting findings, python 3.5 on CentOS 7, I have to vi the Setup file as follow,
# Socket module helper for socket(2)
_socket socketmodule.c

#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

soumyadeep said...

Thanks!

change yum source to SJTU

edit this file, /etc/yum.repos.d/CentOS-Base.repo # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client ...