AnacondaRecipes / python-feedstock

A conda-smithy repository for python.
BSD 3-Clause "New" or "Revised" License
4 stars 7 forks source link

Python 3.7.3 from Anaconda3 cannot make https request or import ssl #19

Open misue123 opened 5 years ago

misue123 commented 5 years ago

I am running a python script using python 3.7.3 from Anaconda 3 installed a week ago. It could not make https request to a simple website like https://www.bing.com with the following error. The python is called from cgi in IIS web server.

Traceback (most recent call last): File "C:\ProgramData\Anaconda3_x64\lib\site-packages\urllib3\connectionpool.py", line 588, in urlopen conn = self._get_conn(timeout=pool_timeout) File "C:\ProgramData\Anaconda3_x64\lib\site-packages\urllib3\connectionpool.py", line 248, in _get_conn return conn or self._new_conn() File "C:\ProgramData\Anaconda3_x64\lib\site-packages\urllib3\connectionpool.py", line 816, in _new_conn 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.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\ProgramData\Anaconda3_x64\lib\site-packages\requests\adapters.py", line 449, in send timeout=timeout File "C:\ProgramData\Anaconda3_x64\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "C:\ProgramData\Anaconda3_x64\lib\site-packages\urllib3\util\retry.py", line 398, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.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."))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\inetpub\wwwroot\demo\myForm.py", line 177, in response = requests.get("https://www.bing.com/") File "C:\ProgramData\Anaconda3_x64\lib\site-packages\requests\api.py", line 75, in get return request('get', url, params=params, kwargs) File "C:\ProgramData\Anaconda3_x64\lib\site-packages\requests\api.py", line 60, in request return session.request(method=method, url=url, kwargs) File "C:\ProgramData\Anaconda3_x64\lib\site-packages\requests\sessions.py", line 533, in request resp = self.send(prep, send_kwargs) File "C:\ProgramData\Anaconda3_x64\lib\site-packages\requests\sessions.py", line 646, in send r = adapter.send(request, kwargs) File "C:\ProgramData\Anaconda3_x64\lib\site-packages\requests\adapters.py", line 514, in send raise SSLError(e, request=request) requests.exceptions.SSLError: 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."))

To troubleshoot, I added "import ssl" in the code, it threw an error as below. However, in conda prompt, there was no error with import ssl, and it points to the same ssl.py.

A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred. I tried this with 32bit and 64 bits Anaconda installation and had the same problem.

C:\inetpub\wwwroot\demo\myForm.py in () 82 import sys

 83 #import dateutil

=> 84 import ssl

 85 

 86 #---------

ssl undefined C:\ProgramData\Anaconda3_x64\lib\ssl.py in () 96 from enum import Enum as _Enum, IntEnum as _IntEnum, IntFlag as _IntFlag

 97 

=> 98 import _ssl # if we can't import it, let the error propagate

 99 

100 from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION

_ssl undefined

ImportError: DLL load failed: The specified module could not be found. args = ('DLL load failed: The specified module could not be found.',) msg = 'DLL load failed: The specified module could not be found.' name = '_ssl' path = r'C:\ProgramData\Anaconda3_x64\DLLs_ssl.pyd' with_traceback =

Note that I also had to update numpy to make the import work for 64bits version, but updating openssl to 1.1.1b did not help.

misue123 commented 5 years ago

In the path near the last few lines, the backslack before _ssl.pyd was eaten by the github posting just in case you wondered.

msarahan commented 5 years ago

You can try the environment variables documented at https://conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#numpy-mkl-library-load-failed, but we really don't support running our python without activation of a conda environment.

misue123 commented 5 years ago

I added the following to the system variables with values of 1. Restarted web server without restarting the machine, still the same. CONDA_DLL_SEARCH_MODIFICATION_ENABLE CONDA_DLL_SEARCH_MODIFICATION_DEBUG CONDA_DLL_SEARCH_MODIFICATION_NEVER_ADD_WINDOWS_DIRECTORY CONDA_DLL_SEARCH_MODIFICATION_NEVER_ADD_CWD

It would be helpful to run python in Anaconda in IIS environment. Luckily I was able to import packages to a standalone python3.7 installation. Then IIS/CGI points to this python without SSL problem.