[python] Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website

Using requests in Python3 Windows via Pycharm, and receiving SSL Module Not Available Error

I've spent hours trying to figure out what could be causing this. I've reinstalled Anaconda, and I am completely stuck. When running the following

def Earlybird(daycount):
    url = 'https://msft.com'
    response = requests.get(url)
    print(response)
Earlybird()

I receive the error

requests.exceptions.SSLError: HTTPSConnectionPool(host='msft.com', 
port=443): Max retries exceeded with url: / (Caused by SSLError("Can't 
connect to HTTPS URL because the SSL module is not available."))

I have no idea what could be causing this. As Anaconda is a recent install, I would assume everything would be up-to-date, so I'm unsure if this is pointing to the wrong SSL ? I am a bit new to python, so thanks for your patience. -

This question is related to python ssl https python-requests pycharm

The answer is


Don't know if this has been solved yet but I was getting similar problems with Anaconda python 3.7.3 and Idle on Windows 10. Fixed it by adding:

<path>\Anaconda3
<path>\Anaconda3\scripts
<path>\Anaconda3\Library\bin

to the PATH variable.


I am on Windows 10, I had the problem with a new fresh installation of Anaconda on python 3.7.4, this post on github solved my problem:

( source: https://github.com/conda/conda/issues/8273)

I cite:

" My workaround: I have copied the following files

libcrypto-1_1-x64.*
libssl-1_1-x64.*

from D:\Anaconda3\Library\bin to D:\Anaconda3\DLLs.

And it works as a charm! "


Windows Users need to set below paths:

  • ..\Anaconda3
  • ..\Anaconda3\scripts
  • ..\Anaconda3\Library\bin

Per user:

  1. Open Environment variable
  2. Click User Variable
  3. Close command prompt if already open and reopen it

System wide (requires restart):

  1. Open Environment variable
  2. Click System Variable
  3. Restart Windows

I got it solved by installing OpenSSL according to the following recommendation: https://github.com/conda/conda/issues/8046#issuecomment-450515815

Corresponding ticket in the conda repository: https://github.com/conda/conda/issues/8046

Update: the problem (in PyCharm) should be solved in 2019.1 version (Early Access Preview build is already available https://www.jetbrains.com/pycharm/nextversion/).


this issue was driving me insane until i found this post which said to do

brew upgrade python3 

(not using pycharm, using sublime)

Error when importing ssl in Python 3.7.4 on macOS 10.14.6


I've installed the binaries from here: https://slproweb.com/products/Win32OpenSSL.html This site is mentioned on the official OpenSSL wiki. It solved my problem


I don't have Anaconda so the steps I took are:

  • brew uninstall python3
  • brew install python3
    • got an error message stating,Your Xcode (10.2) is too outdated. Please update to Xcode 11.3 (or delete it). Xcode can be updated from the App Store.**So, I deleted Xcode since no update would show, then I reinstalled it.
    • ran xcode-select --install after. If you don't.. you'll get an error: The following formula python cannot be installed as binary package and must be built from source. Install the Command Line Tools: xcode-select --install
  • ran brew install python3 and it completed successfully.

Used this script just to see if it works

import requests
r = requests.get('https://www.office.com')
print(r)

Ran the script python3 and python3.7 and output was <Response [200]> instead of SSLError.


I have faced it on 04/2020. These are the options that I tried and the last solution get me through.

Problem:

Requests module works fine when I use in Spyder IDE but when I try to execute the script in windows it fails with SSL error. It works fine for HTTP requests but for HTTPS requests i got SSL error.

  1. I tired with Veify=True, False , also with Certs. Same error.
  2. Removed Certifi - conda remove certifi - Did not work Updated
  3. openssl , certifi - Still same error ( Refer : https://github.com/ContinuumIO/anaconda-issues/issues/494) Added
  4. the path variables - Same error
  5. Created new environment in Anaconda - same error

Solution that fixed it:

Solution from: https://github.com/conda/conda/issues/8273

I have copied the following files from Anaconda3\Library\bin to \Anaconda3\DLL

libcrypto-1_1-x64.* libssl-1_1-x64.*


I had a similar problem on Windows 10 using Conda and Python 2.7.2

After trying many, many solutions I came across this response which suggested that there is an issue with openssl in that build.

Once I downgraded python to 3.7.1 (build h33f27b4_4) everything worked fine.


After dealing with the same issue on Windows 10, the solution is fairly straightforward:

  1. Open an Anaconda Prompt
  2. Run conda init
  3. Close and reopen any open Python interpreters (PyCharm, Anaconda Prompt, cmd, etc.) where you want to run your code

Run your code again and it should work. I had upgraded both Anaconda and PyCharm, and had the issue with all combinations of versions until I ran conda init, which adds to your PATH much like the answer from Paul Stevens . Don't skip #3—restarting PyCharm or any other interpreter is key.


This errors happens in VSCode with Python 3.7.3 but works fine in IDLE editor in Windows 10 with Python 3.7.0.


Make sure you create the project with conda environment option selected.

My problem solved by recreate the project and select "conda" from "New environment using" options

see image:

New environment setting


There is no need to add paths to environment if you use the Anaconda Prompt.

Start the Anaconda prompt change to your directory and run your script or start your editor from there. This will ensure you are in the full Anaconda environment and the SSL error will stop.

Whats the difference between command prompt and Anaconda Prompt? See this SO answer to what is the difference between command prompt and anaconda prompt.


After spending a few hours going through the Anaconda documentation, Github issue tickets and so on, I finally managed to get it working on Windows 10 64-bit (Anaconda 3.7). The thing it worked for me was to install the Win64 OpenSSL v1.1.1d binary file from https://slproweb.com/download/Win64OpenSSL-1_1_1d.exe.

NOTE: The version seems to matter! I have tried the 1.1.0L (as suggested in other comments and responses) but with this version, the problem persisted. If you keep having problems after installing some OpenSSL libs, keep trying until you find the right version. For Anaconda 3.7 on Windows 10 it seems that the right one is the 1.1.1d. I did not try the light version.

Things that did not work for me:


Encountered the same SSL error while doing a pip install after a fresh anaconda installation. What helped was activating the base environment before doing the pip install. Do an activate base from cmd and then run your python script. You can also try 'conda run -n base python script.py' Reference - https://github.com/conda/conda/issues/8487


I had the same thing on my Windows 10 installation.

Anaconda3 would not open Anaconda Navigator before I copied libcrypto-1_1-x64.dll and libssl-1_1-x64.dll from Anaconda3\Library\bin to \Anaconda3\DLL.

Once I did that pip install in the base environment worked fine but not in another environment I created. I had to do the same as above in the new environment.

That is, copy libcrypto-1_1-x64.dll and libssl-1_1-x64.dll from \<env folder>\Library\bin to \<env folder>\DLL then it worked fine.


On Windows 10 - this is a workaround and does not fix the root issue however, if you just need to install something and move on; Execute the following at the command prompt, powershell or dockerfile:

pip config set global.trusted_host "pypi.org files.pythonhosted.org"


I was also facing the same issue in my team mates machines. Fixed the same with adding anaconda path. In my system below is path of Anaconda:

C:\ProgramData\Anaconda3\Scripts
C:\ProgramData\Anaconda3\
C:\ProgramData\Anaconda3\Library\bin

Reinstalling python based on instructions from here solved this problem for me: How can I install a previous version of Python 3 in macOS using homebrew?


Note: This issue was fixed on windows 10 I was facing same issue with virtual environment on windows 10. Issue was solved with running CMD as administrator and creating new virtual environment.

  • Run cmd as administrator
  • create virtual environment (virtualenv .venv )
  • activate virtual environment .venv\Scripts\activate
  • Pip install requests

Solved by doing the following in my windows 10:

mklink "C:\Users\hal\AppData\Local\Continuum\anaconda3\DLLs\libssl-1_1-x64.dll" "C:\Users\hal\AppData\Local\Continuum\anaconda3\Library\bin\libssl-1_1-x64.dll"

mklink "C:\ProgramData\Anaconda3\DLLs\libcrypto-1_1-x64.dll" "C:\ProgramData\Anaconda3\Library\bin\libcrypto-1_1-x64.dll"

I use VSCode to edit and debug and the only solution that worked for me was to edit the environment variables in windows.. Apparently this causes issues but I'm not sure what they are.

Running from the Anaconda prompt (as suggested by sayth) was NOT an option for me. Or perhaps the suggestion was to run the anaconda prompt and the from the anaconda prompt somehow start VSCode. Doesn't sound like a reasonable request.

This appears to be a long running chronic issue without a definitive global answer that works for everyone.


going to the website: gives me following information from developer tool and looking at headers. (right click --> inspect. then open network tab and check headers)

  • Request URL: http://www.msft.com/
  • Request Method: GET
  • Status Code:200 OK
  • Remote Address: 205.178.189.130:80
  • Referrer Policy:no-referrer-when-downgrade

So we see we need to perform a request to HTTP, not HTTPS.

import requests


def Earlybird():
    url = 'http://msft.com/'
    response = requests.get(url)
    print(response.text)

if __name__ == '__main__':
    Earlybird()

I use this "Win64 OpenSSL v1.1.1h" -> EXE from https://slproweb.com/products/Win32OpenSSL.html

i've installed it and works


Questions with python tag:

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Upgrade to python 3.8 using conda Unable to allocate array with shape and data type How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip How to prevent Google Colab from disconnecting? "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm How to fix 'Object arrays cannot be loaded when allow_pickle=False' for imdb.load_data() function? "E: Unable to locate package python-pip" on Ubuntu 18.04 Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session' Jupyter Notebook not saving: '_xsrf' argument missing from post How to Install pip for python 3.7 on Ubuntu 18? Python: 'ModuleNotFoundError' when trying to import module from imported package OpenCV TypeError: Expected cv::UMat for argument 'src' - What is this? Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website How to setup virtual environment for Python in VS Code? Pylint "unresolved import" error in Visual Studio Code Pandas Merging 101 Numpy, multiply array with scalar What is the meaning of "Failed building wheel for X" in pip install? Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed Could not install packages due to an EnvironmentError: [Errno 13] OpenCV !_src.empty() in function 'cvtColor' error ConvergenceWarning: Liblinear failed to converge, increase the number of iterations How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How do I install opencv using pip? How do I install Python packages in Google's Colab? How do I use TensorFlow GPU? How to upgrade Python version to 3.7? How to resolve TypeError: can only concatenate str (not "int") to str How can I install a previous version of Python 3 in macOS using homebrew? Flask at first run: Do not use the development server in a production environment TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array What is the difference between Jupyter Notebook and JupyterLab? Pytesseract : "TesseractNotFound Error: tesseract is not installed or it's not in your path", how do I fix this? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'" How do I resolve a TesseractNotFoundError? Trying to merge 2 dataframes but get ValueError Authentication plugin 'caching_sha2_password' is not supported Python Pandas User Warning: Sorting because non-concatenation axis is not aligned

Questions with ssl tag:

Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website A fatal error occurred while creating a TLS client credential. The internal error state is 10013 curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number How to install OpenSSL in windows 10? ssl.SSLError: tlsv1 alert protocol version Invalid self signed SSL cert - "Subject Alternative Name Missing" "SSL certificate verify failed" using pip to install packages ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel "ssl module in Python is not available" when installing package with pip3 How to add a custom CA Root certificate to the CA Store used by pip in Windows? Letsencrypt add domain to existing certificate bypass invalid SSL certificate in .net core Page loaded over HTTPS but requested an insecure XMLHttpRequest endpoint curl: (35) SSL connect error npm install error - unable to get local issuer certificate Solving sslv3 alert handshake failure when trying to use a client certificate How to force Laravel Project to use HTTPS for all routes? When you use 'badidea' or 'thisisunsafe' to bypass a Chrome certificate/HSTS error, does it only apply for the current site? Warning about SSL connection when connecting to MySQL database How to use TLS 1.2 in Java 6 Could not create SSL/TLS secure channel, despite setting ServerCertificateValidationCallback wget ssl alert handshake failure CFNetwork SSLHandshake failed iOS 9 javax.net.ssl.SSLException: Read error: ssl=0x9524b800: I/O error during system call, Connection reset by peer How to get Python requests to trust a self signed SSL certificate? TLS 1.2 not working in cURL Javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: Failure in SSL library, usually a protocol error cURL error 60: SSL certificate: unable to get local issuer certificate CertPathValidatorException : Trust anchor for certificate path not found - Retrofit Android InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately SSL InsecurePlatform error when using Requests package How to enable TLS 1.2 support in an Android application (running on Android 4.1 JB) SSL peer shut down incorrectly in Java PHP - SSL certificate error: unable to get local issuer certificate Failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED Unable to establish SSL connection upon wget on Ubuntu 14.04 LTS How to set TLS version on apache HttpClient Default SecurityProtocol in .NET 4.5 SSL cert "err_cert_authority_invalid" on mobile chrome only urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error Specifying trust store information in spring boot application.properties List supported SSL/TLS versions for a specific OpenSSL build Creating self signed certificate for domain and subdomains - NET::ERR_CERT_COMMON_NAME_INVALID The client and server cannot communicate, because they do not possess a common algorithm - ASP.NET C# IIS TLS 1.0 / 1.1 / 1.2 - Win32Exception Which versions of SSL/TLS does System.Net.WebRequest support? Disable SSL fallback and use only TLS for outbound connections in .NET? (Poodle mitigation) Chrome disable SSL checking for sites? SSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch file_get_contents(): SSL operation failed with code 1, Failed to enable crypto

Questions with https tag:

What's the net::ERR_HTTP2_PROTOCOL_ERROR about? Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website Android 8: Cleartext HTTP traffic not permitted ssl.SSLError: tlsv1 alert protocol version Invalid self signed SSL cert - "Subject Alternative Name Missing" How do I make a https post in Node Js without any third party module? Page loaded over HTTPS but requested an insecure XMLHttpRequest endpoint How to force Laravel Project to use HTTPS for all routes? Could not create SSL/TLS secure channel, despite setting ServerCertificateValidationCallback Use .htaccess to redirect HTTP to HTTPs Using client certificate in Curl command wget ssl alert handshake failure can you add HTTPS functionality to a python flask web server? How to enable TLS 1.2 support in an Android application (running on Android 4.1 JB) SSL Error: unable to get local issuer certificate Download a file from HTTPS using download.file() Node.js https pem error: routines:PEM_read_bio:no start line GitHub authentication failing over https, returning wrong email address Curl: Fix CURL (51) SSL error: no alternative certificate subject name matches file_get_contents() how to fix error "Failed to open stream", "No such file" How to fix the "java.security.cert.CertificateException: No subject alternative names present" error? How to allow http content within an iframe on a https site Why am I suddenly getting a "Blocked loading mixed active content" issue in Firefox? Access Https Rest Service using Spring RestTemplate How do I disable the security certificate check in Python requests PHP CURL CURLOPT_SSL_VERIFYPEER ignored htaccess redirect to https://www HAProxy redirecting http to https (ssl) Java and HTTPS url connection without downloading certificate Https to http redirect using htaccess How to do a https request with bad certificate? Enabling HTTPS on express.js Powershell v3 Invoke-WebRequest HTTPS error How can I make git accept a self signed certificate? Redirect HTTP to HTTPS on default virtual host without ServerName SOAP-ERROR: Parsing WSDL: Couldn't load from <URL> Why does GitHub recommend HTTPS over SSH? Ignore invalid self-signed ssl certificate in node.js with https.request? How can I see the entire HTTP request that's being sent by my Python application? http to https through .htaccess Server returned HTTP response code: 401 for URL: https SSLHandshakeException: No subject alternative names present https connection using CURL from command line How to force HTTPS using a web.config file Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http] Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error? What is the difference between Digest and Basic Authentication? Insecure content in iframe on secure page How do I fix certificate errors when running wget on an HTTPS URL in Cygwin? Automatic HTTPS connection/redirect with node.js/express

Questions with python-requests tag:

Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website Use python requests to download CSV Download and save PDF file with Python requests module ImportError: No module named 'Queue' How to use cookies in Python Requests Saving response from Requests to file How to get Python requests to trust a self signed SSL certificate? How to install requests module in Python 3.4, instead of 2.7 Upload Image using POST form data in Python-requests SSL InsecurePlatform error when using Requests package How to use Python requests to fake a browser visit a.k.a and generate User Agent? python requests get cookies Max retries exceeded with URL in requests python requests file upload How could I use requests in asyncio? Timeout for python requests.get entire response Python : Trying to POST form using requests Python requests - print entire http request (raw)? Python Requests library redirect new url python ignore certificate validation urllib2 Python requests library how to pass Authorization header with single token How do I read a response from Python Requests? Python Requests package: Handling xml response Sending SOAP request using Python Requests ImportError: No module named requests What's the best way to parse a JSON response from the requests library? Download large file in python with requests Correct way to try/except using Python requests module? Log all requests from the python-requests module Python Request Post with param data Using Python Requests: Sessions, Cookies, and POST How do I disable the security certificate check in Python requests Can I set max_retries for requests.request? Requests -- how to tell if you're getting a 404 Python Requests - No connection adapters Python Requests requests.exceptions.SSLError: [Errno 8] _ssl.c:504: EOF occurred in violation of protocol How to download image using requests Python Requests and persistent sessions How to make python Requests work via socks proxy How can I send an xml body using requests library? How to send a "multipart/form-data" with requests in python? How to "log in" to a website using Python's Requests module? Python: download a file from an FTP server How to install packages offline? How do I disable log messages from the Requests library? Python Requests throwing SSLError Sending "User-agent" using Requests library in Python How can I see the entire HTTP request that's being sent by my Python application? Python-Requests close http connection How to POST JSON data with Python Requests?

Questions with pycharm tag:

"UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website Pycharm/Python OpenCV and CV2 install error Import numpy on pycharm Global npm install location on windows? Pycharm and sys.argv arguments PyCharm error: 'No Module' when trying to import own module (python script) Using (Ana)conda within PyCharm Error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat) when running Python script How to run PyCharm in Ubuntu - "Run in Terminal" or "Run"? ImportError: No module named 'bottle' - PyCharm tkinter: how to use after method Pycharm does not show plot PyCharm import external library Why does pycharm propose to change method to static Pycharm: run only part of my Python file Cannot find reference 'xxx' in __init__.py - Python / Pycharm How do I activate a virtualenv inside PyCharm's terminal? Launch Pycharm from command line (terminal) Unresolved reference issue in PyCharm What is the problem with shadowing names defined in outer scopes? How do I use installed packages in PyCharm? Trying to get PyCharm to work, keep getting "No Python interpreter selected" How to my "exe" from PyCharm project How do I set the maximum line length in PyCharm? How to configure custom PYTHONPATH with VM and PyCharm? pycharm convert tabs to spaces automatically PyCharm shows unresolved references error for valid code pycharm running way slow How to select Python version in PyCharm? How to make PyCharm always show line numbers Is there a difference between using a dict literal and a dict constructor? How do I configure PyCharm to run py.test tests?