4

If I try to execute the following python code

import requests
data = requests.get('https://www.bbc.com')

I get the error message

raise SSLError("Can't connect to HTTPS URL because the SSL "
urllib3.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.

Same python code executed in the anaconda prompt just works fine. So I found this link: A module is working in Anaconda prompt, but not in Spyder

Executing the command given in the stackoverflow post I get the path: C:\Users\x1\Anaconda3\python.exe Calling this path from a windows 10 command line and executing the code above still raises the error.

user47091
  • 373
  • 1
  • 4
  • 14
  • Is the Anaconda version of Python in your environmental variables? – ds_secret Jan 03 '19 at 19:47
  • Yes, I added the mentioned Path. It doesn't even work if I put the whole path (C:\Users\x1\Anaconda3\python.exe to the windows command line to start Python. – user47091 Jan 03 '19 at 21:28
  • What is the path to the script that you're using to start the anaconda prompt? – Xukrao Jan 03 '19 at 21:51
  • I'm using the desktop icon from the windows start menu to execute anaconda prompt. The destination is given as %windir%\System32\cmd.exe "/K" C:\Users\x1\Anaconda3\Scripts\activate.bat C:\Users\x1\Anaconda3 – user47091 Jan 03 '19 at 22:16

3 Answers3

0
  • Open Anaconda Prompt in Admin Mode
  • Run this command conda install -c anaconda requests
  • Install that package
  • Then run your code again. It should work now
0

I had a similar issue where running a python script as a scheduled task would raise this error (whereas running the script from Anaconda Prompt or from Spyder would work as expected). It appears to be a permissions issue. Try to start the Windows Command Line as an administrator (right-click and Run as Administrator). It should work.

To achieve this as a scheduled task, instead of calling a batch file which then called python and then the script, call python directly from the task and add the script as the first argument.

Ben A
  • 3
  • 3
0

I had a similar issue (same error message related to the requests module) with a virtual environment of python 3.8.3 on a windows 10 virtual machine and no admin rights. The solution for me actually was the PATH environment variable as described in the answer of Paul Stevens here: Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website .

So I added the following paths to the environment variable PATH for my user:

  1. Open environment variable for my user (to access the environment variable just type environment variable in your windows search bar.)

  2. Select the PATH variable and klick edit

  3. Add the following paths (replace <path> with your actual path, for me it would be something like C:\Program Files\Anaconda3 etc.):

    • <path>\Anaconda3
    • <path>\Anaconda3\scripts
    • <path>\Anaconda3\Library\bin
  4. Open a new command window

  5. Run your script

And then it magically worked for me.

Btw the print(sys.executable) command would show me the same information in the command and in the anaconda prompt.

Thea
  • 31
  • 7