0

Im using python 3.10.8 in a linux environment(RedHat 7.9 Maipo).' After installing python 3.10.8 manually with all libraries I'm facing this error:

> [root@epnm-lab ~]# python3 
> Python 3.10.8 (main, Oct 14 2022, 02:15:05)
> [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help",
> "copyright", "credits" or "license" for more information.
> >>> import requests
> >>> username = "xxx"
> >>> password = "yyy"
> >>> ip = "zzz"
> >>> requests.get(f"https://{username}:{password}@{ip}/webacs/api/v4/data/Devices?.full=true",
> verify=False)
> Traceback (most recent call last):   File
> "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 692, in urlopen
>     conn = self._get_conn(timeout=pool_timeout)   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 281, in _get_conn
>     return conn or self._new_conn()   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 1011, in _new_conn
>     raise SSLError( 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
> "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line
> 489, in send
>     resp = conn.urlopen(   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 787, in urlopen
>     retries = retries.increment(   File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line
> 592, in increment
>     raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError:
> HTTPSConnectionPool(host='10.88.242.12', port=443): Max retries
> exces?.full=true (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 "<stdin>", line 1, in
> <module>   File
> "/usr/local/lib/python3.10/site-packages/requests/api.py", line 73, in
> get
>     return request("get", url, params=params, **kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in
> request
>     return session.request(method=method, url=url, **kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line
> 587, in request
>     resp = self.send(prep, **send_kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line
> 701, in send
>     r = adapter.send(request, **kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line
> 563, in send
>     raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='10.88.242.12', port=443): Max retries
> exceedefull=true (Caused by SSLError("Can't connect to HTTPS URL
> because the SSL module is not available."))
> >>> [root@epnm-lab ~]#

I've seen in others posts here, but didn't find a solution. I have installed openssl as well.

> [root@epnm-lab-02-ha-01 ~]# rpm -qa|grep ^openssl*
> openssl-1.0.2k-21.el7_9.x86_64 
> openssl-libs-1.0.2k-21.el7_9.x86_64

Is there something wrong with this? Could anyone please help me to solve this issue?

Luiz Polli
  • 21
  • 4
  • maybe it needs also Python module `pyOpenSSL` – furas Oct 21 '22 at 13:15
  • @furas For `pyOpenSSL` is just installation? – Luiz Polli Oct 21 '22 at 14:24
  • on Linux Mint I had only install `pyOpenSSL` and `openssl` but I installed `python3.10` from special repo for `Linux Mint`/`Ubuntu`. Maybe it may need to copy some file `.so` to folder with `urllib` – furas Oct 21 '22 at 14:40
  • I'll try to install pyOpenSSL. Give you a feedback as soon as possible. Thank you my friend – Luiz Polli Oct 21 '22 at 19:07
  • I've installed `pyOpenSSL` but it didn't work. **Any other suggestion?** – Luiz Polli Oct 24 '22 at 14:23
  • other idea: ask Google `"Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available"` :) it gives me [python - Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website - Stack Overflow](https://stackoverflow.com/questions/54135206/requests-caused-by-sslerrorcant-connect-to-https-url-because-the-ssl-module) and there is suggestion to copy some `.so`/`.dll` files to different folders. – furas Oct 24 '22 at 15:22
  • All steps shared in the link above comes from Win10. I'm using redhat 7.9. No idea what I am supposed to do. I've done this before using a lot of criterias to find some solution. Nothing helped. – Luiz Polli Oct 24 '22 at 16:24
  • maybe you should check other results from Google. This link shows that in some situations it needs to move some files in different folder. – furas Oct 24 '22 at 17:05
  • digging in source code of `urllib` I found `import _ssl` and later `print( _ssl.__file__ )` shows me `/usr/lib/python3.10/lib-dynload/_ssl.cpython-310-x86_64-linux-gnu.so` and this is `C/C++` library. Maybe your Python doesn't have this file, and it needs to copy it manually (or it has it with wrong name) – furas Oct 24 '22 at 17:07
  • in source code I see [other comment](https://github.com/urllib3/urllib3/blob/main/src/urllib3/connection.py#L34): `# Compiled with SSL?` If Python was compiled without SSL then it may have problem to use it. – furas Oct 24 '22 at 17:20
  • Let me check the file you mentioned about `_ssl`. I have configured the python manually only with `./configure` `make` `make install` – Luiz Polli Oct 25 '22 at 13:30
  • I could not find anything related to it. `[root@epnm-lab-02-ha-01 urllib]# python3 Python 3.10.8 (main, Oct 14 2022, 02:15:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import ssl Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.10/ssl.py", line 99, in import _ssl # if we can't import it, let the error propagate ModuleNotFoundError: No module named '_ssl' >>> exit() ` Am i missing ssl module? How can this be possible? – Luiz Polli Oct 25 '22 at 15:07
  • did you install from system repo or from page `python.org` using precompiled version (if they exist)? If you would compile source code then it could compile it without `ssl` if it wouldn't find C/C++ library `ssl` and C/C++ headers `*.h`. – furas Oct 25 '22 at 21:14
  • I installed using `XZ` from `python.org`. – Luiz Polli Oct 25 '22 at 23:10
  • I downloaded some `.tar.xz` and it is source code which needs to compile - and if you didn't have installed `ssl` (and `ssl-dev`) before compiling then it could compile it without `ssl`. It may need to compile it again. – furas Oct 25 '22 at 23:32
  • BTW: I found some tutorial [how to install Python on CentOS/Fedora/RedHat](https://tecadmin.net/how-to-install-python-3-10-on-centos-rhel-8-fedora/) and first it installs `openssl-devel` – furas Oct 25 '22 at 23:34
  • Hi @furas. Sorry for the delay in response. I've found a solution. Installing the latest python 3.9.x version. Starting python 3.10 version the supported openssl version package is 1.1.1 and 1.0.2 has been deprecated. After installing 3.9.x the libraries requests and others are working fine. – Luiz Polli Oct 27 '22 at 13:02
  • you could put it as answer below - it can be useful for other users. And later you can mark your answer as accepted. – furas Oct 27 '22 at 13:29
  • Thank you so much @furas for all your support on this. I'll add it as answer below. – Luiz Polli Oct 28 '22 at 10:20

1 Answers1

2

Solved!

The solution for this error is that the python version 3.10 uses openssl version 1.1.1 and my server is using openssl 1.0.2. The openssl version 1.0.2 on python 3.10 has been deprecated. So you need to install python 3.9.x 'cause this version supports openssl 1.0.2.

Hope that helps!

Luiz Polli
  • 21
  • 4