115

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. -

Frank Drin
  • 1,383
  • 2
  • 11
  • 17

23 Answers23

128

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.

Paul Stevens
  • 1,337
  • 1
  • 7
  • 4
  • Although don't know why we have to export multiple paths, but it works for me, thanks. – hui chen Jul 01 '19 at 12:44
  • 1
    THIS WORKED FOR ME! not "execstack ..." cmd but this one! adding path/anaconda3/library/bin worked for me – ERJAN Oct 07 '19 at 16:33
  • 1
    Not sure to understand how/where do we have to add this 3 paths ? – Alex Dana Apr 09 '20 at 15:36
  • Alex - add these items to the PATH environment variable (e.g see Mukesh Methaniya/Neuron answer below) – Paul Stevens Apr 10 '20 at 09:31
  • Where do I have to add these paths? I am trying to run a python code from specific folder using ```python get-pip.py``` – Henry Navarro Apr 28 '20 at 09:24
  • Worked on `Anaconda Python 3.8.3` on a `Windows 10` server. Just had to alter the local `path` environment variable. – EliSquared Feb 08 '21 at 22:05
  • This solution is much better than setting ssl_verify: false as suggested in other posts (e.g., https://stackoverflow.com/questions/42563757/conda-update-condahttperror-http-none). Apparently, that solution has security issues – Tim John Sep 29 '21 at 21:40
  • It seems like my User variables only allow for one PATH, it keeps replacing my old PATH so I can't get all 3. Can Anyone help me? – Micah Oct 14 '21 at 14:17
  • https://stackoverflow.com/questions/60974818/how-to-add-multiple-paths-to-the-system-variable-in-environment-variables-in-win This solved my problem: Use ; to separate each path. – Micah Oct 14 '21 at 14:30
60

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! "

Matt Dnv
  • 1,220
  • 11
  • 22
20

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
Mukesh Methaniya
  • 662
  • 5
  • 13
17

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/).

François B.
  • 993
  • 6
  • 18
Pavel Karateev
  • 6,556
  • 2
  • 27
  • 50
10

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

blah blah
  • 385
  • 4
  • 11
8

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.*

dhina karan
  • 131
  • 1
  • 3
6

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.

codeherk
  • 1,499
  • 14
  • 24
5

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.

Thirumal
  • 5,736
  • 7
  • 40
  • 79
CypherCrypt
  • 81
  • 1
  • 5
4

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.

sayth
  • 6,338
  • 11
  • 52
  • 95
3

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.

kevinmicke
  • 4,943
  • 2
  • 18
  • 22
  • Great thank you for this! VSCode just completed its monthly auto-update on my machine and all of a sudden this problem appeared and your solution worked perfectly :) – Adam DS Sep 03 '21 at 16:57
2

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.

2

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:

zwessels
  • 569
  • 1
  • 9
  • 24
Pablo R. Mier
  • 719
  • 1
  • 7
  • 13
1

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()
NemoMeMeliorEst
  • 443
  • 3
  • 9
1

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

msr
  • 23
  • 5
1

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

ebeb
  • 143
  • 8
1

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

Caconde
  • 3,419
  • 7
  • 29
  • 29
y. bs
  • 58
  • 6
  • Just needed to `Add Interpreter` then to choose `existing environnement` and it did the trick. No need to recreate the project. – Loïc G. Jan 24 '21 at 14:59
1

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
itaishz
  • 681
  • 1
  • 2
  • 10
1

Make sure the command is ran from within the virtual environment; that was my mistake.

6infinity8
  • 170
  • 2
  • 9
1

I had the same problem in VS Code.

The solution was to launch VS Code using Anaconda Prompt.

That is, run Anaconda Prompt, activate your virtual environment if you're using one, and then enter code [working directory].

Denziloe
  • 6,431
  • 3
  • 21
  • 31
0

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
Vikas Sharma
  • 441
  • 2
  • 8
0

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"
Yaakov Bressler
  • 6,210
  • 2
  • 31
  • 51
Hassan
  • 1
0

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.

  • Not sure what "not a reasonable request" means, but it is actually generally good practice for avoiding weird errors, and it resolves this error too. It's not hard, just enter `code` in the prompt to launch VS Code. – Denziloe Jun 24 '21 at 18:21
0

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"