How To Fix SSLError Can’t connect to HTTPS URL because the SSL module is not available

During the process of python development, I meet the SSLError Can’t connect to HTTPS URL because the SSL module is not available in several cases. In this article, I will tell you how to reproduce and fix this error with examples.

1. Case1: Meet The Error When Executing Pip Install Command In Eclipse.

  1. I want to import the python pandas module in my python source code, when I run the python source code in the Eclipse PyDev project, it shows an error on the line of the source code import pandas as pd.
  2. The error message is Unresolved import: pd. This means that the python interpreter which I used in my eclipse PyDev project does not install the pandas module.

1.1 Steps To Reproduce The Can’t Connect To HTTPS URL Because The SSL Module Is Not Available Error.

  1. I follow the article How To Install Python Library ( such as Pandas ) In PyCharm, PyDev Eclipse to install the python pandas library in my Eclipse PyDev project.
  2. When I run the command install pandas in the Manage pip window ( please refer to the above article section 2.2 ), it shows the bellow error message in the text area under the Command to execute input text box.
    WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pandas/
    WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pandas/
    WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pandas/
    WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pandas/
    WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pandas/
    ERROR: Could not find a version that satisfies the requirement pandas (from versions: none)
    ERROR: No matching distribution found for pandas
    Could not fetch URL https://pypi.org/simple/pandas/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pandas/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
    FINISHED
  3. This error confused me a lot of time, but after investigating, I finally find the method to fix it.

1.2 How To Fix The Can’t Connect To HTTPS URL Because The SSL Module Is Not Available Error.

  1. I use the Anaconda in my example, and my python interpreter is an anaconda virtual environment also.
  2. First I open a dos window and run the command conda info to get the Anaconda basic information such as the Anaconda home directory ( it is C:\Users\zhaosong\anaconda3 in this example ).
    C:\Users\zhaosong>conda info
    
         active environment : None
           user config file : C:\Users\zhaosong\.condarc
     populated config files : C:\Users\zhaosong\.condarc
              conda version : 4.10.1
        conda-build version : 3.20.5
             python version : 3.8.5.final.0
           virtual packages : __win=0=0
                              __archspec=1=x86_64
           base environment : C:\Users\zhaosong\anaconda3  (writable)
          conda av data dir : C:\Users\zhaosong\anaconda3\etc\conda
      conda av metadata url : https://repo.anaconda.com/pkgs/main
               channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                              https://repo.anaconda.com/pkgs/main/noarch
                              https://repo.anaconda.com/pkgs/r/win-64
                              https://repo.anaconda.com/pkgs/r/noarch
                              https://repo.anaconda.com/pkgs/msys2/win-64
                              https://repo.anaconda.com/pkgs/msys2/noarch
              package cache : C:\Users\zhaosong\anaconda3\pkgs
                              C:\Users\zhaosong\.conda\pkgs
                              C:\Users\zhaosong\AppData\Local\conda\conda\pkgs
           envs directories : C:\Users\zhaosong\anaconda3\envs
                              C:\Users\zhaosong\.conda\envs
                              C:\Users\zhaosong\AppData\Local\conda\conda\envs
                   platform : win-64
                 user-agent : conda/4.10.1 requests/2.24.0 CPython/3.8.5 Windows/10 Windows/10.0.19041
              administrator : False
                 netrc file : None
               offline mode : False
  3. I add the below 3 paths to my Windows Path environment variable value, then the error is fixed. You should use your own Anaconda path value to replace the one in my example. You can refer to the article How To Set Windows Environment Variables to learn more.
    C:\Users\zhaosong\anaconda3
    
    C:\Users\zhaosong\anaconda3\Scripts
    
    C:\Users\zhaosong\anaconda3\Library\bin

2. Case 2: Meet The Error When Using Python Urllib3 To Get Webpage Html With HTTPS URL.

  1. When I use the python module urllib3 to retrieve a webpage Html source code using an HTTPS web page URL, it also throws an error like the above.
  2. Below is the detailed error stack trace.
    Exception has occurred: MaxRetryError
    HTTPSConnectionPool(host='www.bing.com', port=443): Max retries exceeded with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
  3. In this case, I also use anaconda as the python environment and the editor is visual studio code, and after I add the below 3 strings in the windows PATH system environment variable, the error is fixed also, you can refer to section 1.2 of this article to get the detailed explanation.
    C:\Users\zhaosong\anaconda3
    
    C:\Users\zhaosong\anaconda3\Scripts
    
    C:\Users\zhaosong\anaconda3\Library\bin

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.